Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
google::cloud::pubsub::AckHandler Class Reference

Defines the interface to acknowledge and reject messages. More...

#include <google/cloud/pubsub/ack_handler.h>

Classes

class  Impl
 Allow applications to mock an AckHandler. More...
 

Public Member Functions

 ~AckHandler ()
 
 AckHandler (AckHandler &&)=default
 
AckHandleroperator= (AckHandler &&)=default
 
void ack () &&
 Acknowledges the message associated with this handler. More...
 
void nack () &&
 Rejects the message associated with this handler. More...
 
std::int32_t delivery_attempt () const
 Returns the approximate number of times that Cloud Pub/Sub has attempted to deliver the associated message to a subscriber. More...
 
 AckHandler (std::unique_ptr< Impl > impl)
 Applications may use this constructor in their mocks. More...
 

Detailed Description

Defines the interface to acknowledge and reject messages.

When applications register a callback to receive Pub/Sub messages the callback must be able to receive both a pubsub::Message and its associated pubsub::AckHandler. Actions on a pubsub::AckHandler always affect the same message received in the callback. Applications cannot create standalone handlers (except in unit tests via mocks).

This interface allows applications to acknowledge and reject messages that are provided by the Cloud Pub/Sub C++ client library to the application. Note that this class is move-able, to support applications that process messages asynchronously. However, this class is not copy-able, because messages can only be acknowledged or rejected exactly once.

Thread Safety
This class is thread compatible, only one thread should call non-const member functions of this class at a time. Note that because the non-const member functions are && overloads the application can only call ack() or nack() exactly once, and only one of them.

Constructor & Destructor Documentation

◆ ~AckHandler()

google::cloud::pubsub::AckHandler::~AckHandler ( )

◆ AckHandler() [1/2]

google::cloud::pubsub::AckHandler::AckHandler ( AckHandler &&  )
default

◆ AckHandler() [2/2]

google::cloud::pubsub::AckHandler::AckHandler ( std::unique_ptr< Impl impl)
inlineexplicit

Applications may use this constructor in their mocks.

Member Function Documentation

◆ ack()

void google::cloud::pubsub::AckHandler::ack ( ) &&
inline

Acknowledges the message associated with this handler.

Idempotency
Note that this is not an idempotent operation, and therefore it is never retried. Furthermore, the service may still resend a message after a successful ack(). Applications developers are reminded that Cloud Pub/Sub offers "at least once" semantics so they should be prepared to handle duplicate messages.

◆ delivery_attempt()

std::int32_t google::cloud::pubsub::AckHandler::delivery_attempt ( ) const
inline

Returns the approximate number of times that Cloud Pub/Sub has attempted to deliver the associated message to a subscriber.

◆ nack()

void google::cloud::pubsub::AckHandler::nack ( ) &&
inline

Rejects the message associated with this handler.

Idempotency
Note that this is not an idempotent operation, and therefore it is never retried. Furthermore, the service may still resend a message after a successful nack(). Applications developers are reminded that Cloud Pub/Sub offers "at least once" semantics so they should be prepared to handle duplicate messages.

◆ operator=()

AckHandler & google::cloud::pubsub::AckHandler::operator= ( AckHandler &&  )
default