Class ExactlyOnceAckHandler (2.16.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::ExactlyOnceAckHandler. Actions on a pubsub::ExactlyOnceAckHandler 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

ExactlyOnceAckHandler(ExactlyOnceAckHandler &&)

Parameter
Name Description
ExactlyOnceAckHandler &&

ExactlyOnceAckHandler(std::unique_ptr< Impl >)

Applications may use this constructor in their mocks.

Parameter
Name Description
impl std::unique_ptr< Impl >

Operators

operator=(ExactlyOnceAckHandler &&)

Parameter
Name Description
ExactlyOnceAckHandler &&
Returns
Type Description
ExactlyOnceAckHandler &

Functions

ack() &&

Acknowledges the message associated with this handler.

Idempotency

If exactly-once is enabled in the subscription, the client library will retry this operation in the background until it succeeds, fails with a permanent error, or the ack id has become unusable (all ack ids are unusable after 10 minutes). The returned future is satisfied when the retry loop completes. If exactly-once is not enabled, the request is handled on a best-effort basis.

If the future is satisfied with an Okay Statusand exactly-once delivery is enabled in the subscription, then the message will not be resent by Cloud Pub/Sub. We remind the reader that Cloud Pub/Sub defaults to "at least once" delivery, that is, without exactly-once delivery, the message may be resent even after the future is satisfied with an Okay Status.

If the future is satisfied with an error, it is possible that Cloud Pub/Sub never received the acknowledgement, and will resend the message.

Returns
Type Description
future< Status >

nack() &&

Rejects the message associated with this handler.

Idempotency

If exactly-once is enabled in the subscription, the client library will retry this operation in the background until it succeeds, fails with a permanent error, or the ack id has become unusable (all ack ids are unusable after 10 minutes). The returned future is satisfied when the retry loop completes. If exactly-once is not enabled, the request is handled on a best-effort basis.

In any case, Cloud Pub/Sub will eventually resend the message. It might do so sooner if the operation succeeds.

Returns
Type Description
future< Status >

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