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

#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:
+ Collaboration diagram for urabbitmq::ConsumerComponentBase:

Public Member Functions

 ConsumerComponentBase (const components::ComponentConfig &config, const components::ComponentContext &context)
 
- Public Member Functions inherited from components::LoggableComponentBase
 LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
 
 LoggableComponentBase (LoggableComponentBase &&)=delete
 
 LoggableComponentBase (const LoggableComponentBase &)=delete
 
 ~LoggableComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Static Public Member Functions

static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 

Protected Member Functions

void OnAllComponentsLoaded () final
 
void OnAllComponentsAreStopping () final
 
virtual void Process (std::string message)=0
 Override this method in derived class and implement message handling logic.
 

Member Function Documentation

◆ Process()

virtual void urabbitmq::ConsumerComponentBase::Process ( std::string message)
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.


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