#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) |
You may override this method in derived class and implement message handling logic. By default it does nothing. | |
virtual void | Process (ConsumedMessage msg) |
You may override this method in derived class and implement message handling logic. By default it just calls Process(std::string) with message body. | |
|
inlineprotectedvirtual |
You may override this method in derived class and implement message handling logic. By default it just calls Process(std::string)
with message body.
Definition at line 77 of file consumer_base.hpp.
|
inlineprotectedvirtual |
You may override this method in derived class and implement message handling logic. By default it does nothing.
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.
Definition at line 70 of file consumer_base.hpp.
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.