userver: urabbitmq::ConsumerComponentBase Class Reference
Loading...
Searching...
No Matches
urabbitmq::ConsumerComponentBase Class Reference

#include <userver/urabbitmq/consumer_component_base.hpp>

Detailed Description

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.

Note
Library guarantees at least once delivery, hence some deduplication might be needed ou your side.

Static configuration example:

# yaml
my-consumer:
rabbit_name: my-rabbit
queue: sample-queue
prefetch_count: 5

Static options:

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.

+ Inheritance diagram for urabbitmq::ConsumerComponentBase:

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.
 

Member Typedef Documentation

◆ LoggableComponentBase

using components::ComponentBase::LoggableComponentBase = ComponentBase
protectedinherited

Legacy alias, use ComponentBase instead.

Definition at line 69 of file component_base.hpp.

Member Function Documentation

◆ GetComponentHealth()

ComponentHealth components::ComponentBase::GetComponentHealth ( ) const
inlineoverridevirtualinherited

Override this function to inform the world of the state of your component.

Warning
The function is called concurrently from multiple threads.

Reimplemented from components::RawComponentBase.

Definition at line 35 of file component_base.hpp.

◆ OnAllComponentsAreStopping()

void urabbitmq::ConsumerComponentBase::OnAllComponentsAreStopping ( )
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.

◆ OnAllComponentsLoaded()

void urabbitmq::ConsumerComponentBase::OnAllComponentsLoaded ( )
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.

◆ OnLoadingCancelled()

void components::ComponentBase::OnLoadingCancelled ( )
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 44 of file component_base.hpp.

◆ Process() [1/2]

virtual void urabbitmq::ConsumerComponentBase::Process ( ConsumedMessage msg)
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 74 of file consumer_component_base.hpp.

◆ Process() [2/2]

virtual void urabbitmq::ConsumerComponentBase::Process ( std::string )
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 67 of file consumer_component_base.hpp.


The documentation for this class was generated from the following file: