Class AckHandler (2.26.0)

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.

Constructors

AckHandler(AckHandler &&)

Parameter
Name Description
AckHandler &&

AckHandler(std::unique_ptr< Impl >)

Applications may use this constructor in their mocks.

Parameter
Name Description
impl std::unique_ptr< Impl >

Operators

operator=(AckHandler &&)

Parameter
Name Description
AckHandler &&
Returns
Type Description
AckHandler &

Functions

ack() &&

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.

Returns
Type Description
void

nack() &&

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.

Returns
Type Description
void

delivery_attempt() const

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

Returns
Type Description
std::int32_t