Google Cloud Pub/Sub C++ Client  1.32.1
A C++ Client Library for Google Cloud Pub/Sub
Classes | Public Member Functions | List of all members
google::cloud::pubsub::v1::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 in a provided to the Cloud Pub/Sub C++ client library. 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.

Definition at line 48 of file ack_handler.h.

Constructor & Destructor Documentation

◆ ~AckHandler()

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

Definition at line 32 of file ack_handler.cc.

◆ AckHandler() [1/2]

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

◆ AckHandler() [2/2]

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

Applications may use this constructor in their mocks.

Definition at line 104 of file ack_handler.h.

Member Function Documentation

◆ ack()

void google::cloud::pubsub::v1::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.

Definition at line 65 of file ack_handler.h.

◆ delivery_attempt()

std::int32_t google::cloud::pubsub::v1::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.

Definition at line 87 of file ack_handler.h.

◆ nack()

void google::cloud::pubsub::v1::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.

Definition at line 80 of file ack_handler.h.

◆ operator=()

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