Cloud Pub/Sub v1 API - Class SubscriptionHandler (3.8.0)

public abstract class SubscriptionHandler

Reference documentation and code samples for the Cloud Pub/Sub v1 API class SubscriptionHandler.

This abstract class provides the message handler to handle and process the messages. It also provides the ACKnowledge (ACK) and Not ACKnowledge (NACK) response handlers which indicates the ACK/NACK status of each message for the subscription. The users of subscription should inherit from this class and provide their implementation to handle messages and their acknowledgement response.

Inheritance

object > SubscriptionHandler

Namespace

Google.Cloud.PubSub.V1

Assembly

Google.Cloud.PubSub.V1.dll

Methods

HandleAckResponses(IReadOnlyList<AckNackResponse>)

public virtual void HandleAckResponses(IReadOnlyList<AckNackResponse> responses)

This handler function is called when an ACKnowledge (ACK) operation returns, indicating the status of successful or permanently failed messages.

Parameter
NameDescription
responsesIReadOnlyListAckNackResponse

The read-only collection of the AckNackResponse indicating the Ack status of successful or permanently failed messages. This collection may be empty but never null. For exactly once delivery subscription, this collection contains only the successful or permanently failed messages. In this case, the messages that have failed with temporary errors are not included in this collection as their status may change in the future. For non-exactly once subscriptions, this collection contains the ACK status as success for all the messages. In this case, a message may appear multiple times with the same status.

Remarks

The default implementation of this method does nothing. The users of subscription should override this method to handle the ACK response for exactly once delivery subscriptions. This is optional for non-exactly once delivery subscriptions.

Any exception thrown from this method will terminate the SubscriberClient.

HandleMessage(PubsubMessage, CancellationToken)

public abstract Task<SubscriberClient.Reply> HandleMessage(PubsubMessage message, CancellationToken cancellationToken)

The handler function that is passed all received messages. This function may be called on multiple threads concurrently. Return Ack from this function to ACKnowledge this message (implying it won't be received again); or return Nack to Not ACKnowledge this message (implying it will be received again). If this function throws any Exception, then it behaves as if it returned Nack.

Parameters
NameDescription
messagePubsubMessage
cancellationTokenCancellationToken
Returns
TypeDescription
TaskSubscriberClientReply
Remarks

The users of subscription must implement this function to handle the messages.

HandleNackResponses(IReadOnlyList<AckNackResponse>)

public virtual void HandleNackResponses(IReadOnlyList<AckNackResponse> responses)

This handler function is called when a Not ACKnowledge (NACK) operation returns, indicating the status of successful or permanently failed messages.

Parameter
NameDescription
responsesIReadOnlyListAckNackResponse

The read-only collection of the AckNackResponse indicating the Nack status of successful or permanently failed messages. This collection may be empty but never null. For exactly once delivery subscription, this collection contains only the successful or permanently failed messages. In this case, the messages that have failed with temporary errors are not included in this collection as their status may change in the future. For non-exactly once subscriptions, this collection contains the NACK status as success for all the messages. In this case, a message may appear multiple times with the same status.

Remarks

The default implementation of this method does nothing. The users of subscription should override this method to handle the NACK response for exactly once delivery subscriptions. This is optional for non-exactly once delivery subscriptions.

Any exception thrown from this method will terminate the SubscriberClient.