#include <userver/urabbitmq/consumer_base.hpp>
Base class for your consumers. You should derive from it and override Process
method, which gets called when a new message arrives from the broker.
If your configuration is known upfront and doesn't change ar runtime consider using ConsumerComponentBase
instead.
Library takes care of handling start failures and runtime failures (connection breakage/broker node downtime etc.) and will try it's best to restart the consumer.
Stop
before derived class is destroyed, otherwise a race is possible, when Process
is called concurrently with derived class destructor, which is UB.at least once
delivery, hence some deduplication might be needed ou your side. Definition at line 39 of file consumer_base.hpp.
Public Member Functions | |
ConsumerBase (std::shared_ptr< Client > client, const ConsumerSettings &settings) | |
void | Start () |
Start consuming messages from the broker. Calling this method on running consumer has no effect. | |
void | Stop () |
Stop consuming messages from the broker. Calling this method on stopped consumer has no effect. | |
Protected Member Functions | |
virtual void | Process (std::string message)=0 |
Override this method in derived class and implement message handling logic. | |
|
protectedpure virtual |
Override this method in derived class and implement message handling logic.
If this method returns successfully message would be acked (best effort) to the broker, if this method throws the message would be requeued.
Please keep in mind that it is possible for the message to be delivered again even if Process
returns successfully: sadly we can't guarantee that ack
ever reached the broker (network issues or unexpected shutdown, for example). It is however guaranteed for message to be requeued if Process
fails.
void urabbitmq::ConsumerBase::Start | ( | ) |
Start consuming messages from the broker. Calling this method on running consumer has no effect.
Should not throw, in case of initial setup failure library will restart the consumer in the background.
void urabbitmq::ConsumerBase::Stop | ( | ) |
Stop consuming messages from the broker. Calling this method on stopped consumer has no effect.