RMQ - RabbitMQ C++ Library
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
BloombergLP::rmqa::MessageGuard Class Reference

Controls acknowledgements passed to broker for consumed messages. More...

#include <rmqa_messageguard.h>

Inheritance diagram for BloombergLP::rmqa::MessageGuard:
Inheritance graph
[legend]
Collaboration diagram for BloombergLP::rmqa::MessageGuard:
Collaboration graph
[legend]

Classes

class  Factory
 

Public Types

typedef bsl::function< void(const rmqt::ConsumerAck &)> MessageGuardCallback
 

Public Member Functions

 MessageGuard (const rmqt::Message &message, const rmqt::Envelope &envelope, const MessageGuardCallback &ackCallback, rmqp::Consumer *consumer)
 
 MessageGuard (const MessageGuard &obj)
 
 ~MessageGuard () BSLS_KEYWORD_OVERRIDE
 
const rmqt::Messagemessage () const BSLS_KEYWORD_OVERRIDE
 Access the received message. More...
 
const rmqt::Envelopeenvelope () const BSLS_KEYWORD_OVERRIDE
 Access the received message envelope (delivery details) More...
 
void ack () BSLS_KEYWORD_OVERRIDE
 
void nack (bool requeue=true) BSLS_KEYWORD_OVERRIDE
 
virtual rmqp::Consumerconsumer () const BSLS_KEYWORD_OVERRIDE
 Pointer to the Consumer, e.g. to cancel the message flow. More...
 
rmqp::TransferrableMessageGuard transferOwnership () BSLS_KEYWORD_OVERRIDE
 

Protected Types

enum  State { READY , TRANSFERRED , RESOLVED }
 

Protected Member Functions

State state () const
 

Friends

bsl::ostream & operator<< (bsl::ostream &os, const MessageGuard &mg)
 Stream out.
 

Detailed Description

Controls acknowledgements passed to broker for consumed messages.

A MessageGuard is passed to the rmqa::Consumer callback function (defined in rmqp::Consumer) for each message. The object allows acknowledging either positively or negatively, with options to requeue. If a MessageGuard object is allowed to destruct before ack/nack is called a nack with requeue is automatically signaled to the broker.

Member Enumeration Documentation

◆ State

Ready - not resolved yet Invalid - ownership moved Resolved - message (n)acked.

Constructor & Destructor Documentation

◆ MessageGuard() [1/2]

BloombergLP::rmqa::MessageGuard::MessageGuard ( const rmqt::Message message,
const rmqt::Envelope envelope,
const MessageGuardCallback &  ackCallback,
rmqp::Consumer consumer 
)

Constructs a new valid guard

Parameters
messageConsumed message
envelopeConsumed delivery metadata
ackCallbackCallback called when resolving message
consumerPointer to the Consumer

◆ MessageGuard() [2/2]

BloombergLP::rmqa::MessageGuard::MessageGuard ( const MessageGuard obj)

During copying obj is invalidated and thereafter cannot be used to (n)ack.

◆ ~MessageGuard()

BloombergLP::rmqa::MessageGuard::~MessageGuard ( )
virtual

If not processed (ack()/nack() called), message will be nacked automatically.

Reimplemented from BloombergLP::rmqp::MessageGuard.

Member Function Documentation

◆ ack()

void BloombergLP::rmqa::MessageGuard::ack ( )
virtual

Acknowledge the received message. Callable only once. Should only be called after the message has been fully processed

A message acknowledgement is fire-and-forget. If the broker does not receive this (e.g. due to connection drop), the message will be redelivered to another consumer.

Implements BloombergLP::rmqp::MessageGuard.

◆ consumer()

rmqp::Consumer * BloombergLP::rmqa::MessageGuard::consumer ( ) const
virtual

Pointer to the Consumer, e.g. to cancel the message flow.

Implements BloombergLP::rmqp::MessageGuard.

◆ envelope()

const rmqt::Envelope & BloombergLP::rmqa::MessageGuard::envelope ( ) const
virtual

Access the received message envelope (delivery details)

Implements BloombergLP::rmqp::MessageGuard.

◆ message()

const rmqt::Message & BloombergLP::rmqa::MessageGuard::message ( ) const
virtual

Access the received message.

Implements BloombergLP::rmqp::MessageGuard.

◆ nack()

void BloombergLP::rmqa::MessageGuard::nack ( bool  requeue = true)
virtual

Negative acknowledge the received message. Callable only once.

Parameters
requeuetrue requeues the message on the broker for redelivery , if false, then the message will be either dead lettered (if a dead letter exchange is specified) or dropped if not.

Implements BloombergLP::rmqp::MessageGuard.

◆ transferOwnership()

rmqp::TransferrableMessageGuard BloombergLP::rmqa::MessageGuard::transferOwnership ( )
virtual

Transfers ownership of the message processing to a MessageGuard that is copyable (shared pointer semantics) RETURN a shared pointer to a valid message guard,

Note
if the MessageGuard has already been resolved or transferred (ack/nack) a warning will be printed

Implements BloombergLP::rmqp::MessageGuard.

Reimplemented in BloombergLP::rmqa::TracingMessageGuard.


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