# Cloud Pub/Sub v1 API - Class SubscriptionHandler (3.36.0)

3.36.0 (latest) 3.35.0 3.34.0 3.33.0 3.32.0 3.31.0 3.30.0 3.29.0 3.28.0 3.27.0 3.26.0 3.25.0 3.24.0 3.23.0 3.22.0 3.21.0 3.20.0 3.19.0 3.18.0 3.17.0 3.16.0 3.15.0 3.14.0 3.13.0 3.12.0 3.11.0 3.10.1 3.9.1 3.8.0 3.7.0 3.6.0 3.5.1 3.4.0 3.3.0 3.2.0 3.1.0 3.0.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.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](https://learn.microsoft.com/dotnet/api/system.object) \> SubscriptionHandler

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.PubSub.V1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/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** ||
|---|---|
| **Name** | **Description** |
| `responses` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.AckNackResponse` The read-only collection of the [AckNackResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.AckNackResponse) indicating the [Ack](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply#Google_Cloud_PubSub_V1_SubscriberClient_Reply_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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply#Google_Cloud_PubSub_V1_SubscriberClient_Reply_Ack) from this function
to ACKnowledge this message (implying it won't be received again); or return [Nack](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply#Google_Cloud_PubSub_V1_SubscriberClient_Reply_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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply#Google_Cloud_PubSub_V1_SubscriberClient_Reply_Nack).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage` |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClienthttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply` |   |

**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** ||
|---|---|
| **Name** | **Description** |
| `responses` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.AckNackResponse` The read-only collection of the [AckNackResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.AckNackResponse) indicating the [Nack](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply#Google_Cloud_PubSub_V1_SubscriberClient_Reply_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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient).