#include <userver/urabbitmq/consumer_component_base.hpp>
Base component for your consumers. Basically a ConsumerBase
but in a nice component-ish way.
You should derive from it and override Process
method, which gets called when a new message arrives from the broker. The consumer will be automatically started after all components are loaded and stopped before all components are beginning to stop.
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.
at least once
delivery, hence some deduplication might be needed ou your side.Name | Description rabbit_name | Name of the RabbitMQ component to use for consumption queue | Name of the queue to consume from prefetch_count | prefetch_count for the consumer, limits the amount of in-flight messages
Definition at line 43 of file consumer_component_base.hpp.
Public Member Functions | |
ConsumerComponentBase (const components::ComponentConfig &config, const components::ComponentContext &context) | |
ComponentHealth | GetComponentHealth () const override |
void | OnLoadingCancelled () override |
Static Public Member Functions | |
static yaml_config::Schema | GetStaticConfigSchema () |
Protected Types | |
using | LoggableComponentBase = ComponentBase |
Legacy alias, use ComponentBase instead. | |
Protected Member Functions | |
void | OnAllComponentsLoaded () final |
void | OnAllComponentsAreStopping () final |
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 with message body. | |
|
protectedinherited |
Legacy alias, use ComponentBase instead.
Definition at line 67 of file component_base.hpp.
|
inlineoverridevirtualinherited |
Override this function to inform the world of the state of your component.
Reimplemented from components::RawComponentBase.
Reimplemented in server::handlers::Restart.
Definition at line 35 of file component_base.hpp.
|
finalprotectedvirtual |
Component may use this function to stop doing work before the stop of the components that depend on it.
Base components may override it and make final
to do some work before the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::ComponentBase.
|
finalprotectedvirtual |
Component may use this function to finalize registration of other components that depend on it (for example, handler components register in server component, and the latter uses OnAllComponentsLoaded() to start processing requests).
Base components may override it and make final
to do some work after the derived object constructor is called. Don't use it otherwise.
Reimplemented from components::ComponentBase.
|
inlineoverridevirtualinherited |
Called once if the creation of any other component failed. If the current component expects some other component to take any action with the current component, this call is a signal that such action may never happen due to components loading was cancelled. Application components might not want to override it.
Reimplemented from components::RawComponentBase.
Definition at line 42 of file component_base.hpp.
|
inlineprotectedvirtual |
You may override this method in derived class and implement message handling logic. By default it just calls Process
with message body.
Definition at line 73 of file consumer_component_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 66 of file consumer_component_base.hpp.