# Cloud Pub/Sub v1 API - Class SubscriberClient (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 SubscriberClient : IAsyncDisposable

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

A PubSub subscriber that is associated with a specific [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName).

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> SubscriberClient

## Implements

[IAsyncDisposable](https://learn.microsoft.com/dotnet/api/system.iasyncdisposable)

## 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)

## Derived Types

[SubscriberClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClientImpl)

## 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

## Remarks

To receive messages, the [StartAsync(SubscriptionHandler)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_StartAsync_Google_Cloud_PubSub_V1_SubscriptionHandler_) method must be called,
with a suitable message handler.

The message handler [SubscriberClient.Reply](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Reply) states whether to acknowledge the message;
if acknowledged then (under normal conditions) it will not be received on this subscription again.

But note that it is always possible to receive duplicate messages. This services
guarantees "at least once" delivery, not "only once" delivery.


This class implements the [IAsyncDisposable](https://learn.microsoft.com/dotnet/api/system.iasyncdisposable) interface. However, it is recommended to create a single `SubscriberClient` instance, and use it throughout
the lifetime of the application. If the `SubscriberClient` is registered in a dependency injection container, its
`DisposeAsync` method will be called automatically.

## Properties

### DefaultAckDeadline

    public static TimeSpan DefaultAckDeadline { get; }

The default message acknowledgement deadline of 60 seconds.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### DefaultAckDeadlineForExactlyOnceDelivery

    public static TimeSpan DefaultAckDeadlineForExactlyOnceDelivery { get; }

The default message acknowledgement deadline of 60 seconds for exactly-once delivery subscriptions.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### DefaultAckExtensionWindow

    public static TimeSpan DefaultAckExtensionWindow { get; }

The default message acknowledgement extension window of 15 seconds.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### DefaultDisposeTimeout

    public static TimeSpan DefaultDisposeTimeout { get; }

The default [DisposeTimeout](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings#Google_Cloud_PubSub_V1_SubscriberClient_Settings_DisposeTimeout) of 5 seconds for the [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### DefaultFlowControlSettings

    public static FlowControlSettings DefaultFlowControlSettings { get; }

Default [FlowControlSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.FlowControlSettings.html) for [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient).
Allows 1,000 outstanding messages; and 100Mb outstanding bytes.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.FlowControlSettings.html` | Default [FlowControlSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.FlowControlSettings.html) for [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient). |

### DefaultMaxTotalAckExtension

    public static TimeSpan DefaultMaxTotalAckExtension { get; }

The default maximum total acknowledgement extension of 60 minutes.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### MaximumAckDeadline

    public static TimeSpan MaximumAckDeadline { get; }

The service-defined maximum message acknowledgement deadline of 10 minutes.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### MinimumAckDeadline

    public static TimeSpan MinimumAckDeadline { get; }

The service-defined minimum message acknowledgement deadline of 10 seconds.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### MinimumAckExtensionWindow

    public static TimeSpan MinimumAckExtensionWindow { get; }

The minimum message acknowledgement extension window of 50 milliseconds.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### MinimumAckExtensionWindowForExactlyOnceDelivery

    [Obsolete("Use DefaultAckDeadlineForExactlyOnceDelivery instead.")]
    public static TimeSpan MinimumAckExtensionWindowForExactlyOnceDelivery { get; }

The minimum message acknowledgement extension window of 60 seconds for exactly once delivery subscriptions.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

**Remarks** This property is deprecated. Use [DefaultAckDeadlineForExactlyOnceDelivery](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_DefaultAckDeadlineForExactlyOnceDelivery) instead.

### MinimumLeaseExtensionDelay

    public static TimeSpan MinimumLeaseExtensionDelay { get; }

The enforced 5 second minimum duration between obtaining a lease on a message and when a lease extension can be requested.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### SubscriptionName

    public virtual SubscriptionName SubscriptionName { get; }

The associated [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionName` |   |

## Methods

### Create(SubscriptionName)

    public static SubscriberClient Create(SubscriptionName subscriptionName)

Create a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName), using default settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `subscriptionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionName` The [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName) to receive messages from. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient` | A [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName). |

### Create(SubscriptionName, ClientCreationSettings, Settings)

    [Obsolete("Use SubscriberClient.Create(SubscriptionName) to use the default settings, or SubscriberClientBuilder for customization.")]
    public static SubscriberClient Create(SubscriptionName subscriptionName, SubscriberClient.ClientCreationSettings clientCreationSettings = null, SubscriberClient.Settings settings = null)

Create a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName).
The default `settings` and `clientCreationSettings` are suitable for machines with
high network bandwidth (e.g. Google Compute Engine instances). If running with more limited network bandwidth, some
settings may need changing; especially [AckDeadline](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings#Google_Cloud_PubSub_V1_SubscriberClient_Settings_AckDeadline).
By default this method generates a gRPC channel per CPU core; if using a high-core-count machine and using many
clients concurrently then this may need reducing; use the setting [ClientCount](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.ClientCreationSettings#Google_Cloud_PubSub_V1_SubscriberClient_ClientCreationSettings_ClientCount).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `subscriptionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionName` The [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName) to receive messages from. |
| `clientCreationSettings` | `https://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.ClientCreationSettings` Optional. [SubscriberClient.ClientCreationSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.ClientCreationSettings) specifying how to create [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient)s. |
| `settings` | `https://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.Settings` Optional. [SubscriberClient.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings) for creating a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient` | A [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName). |

### CreateAsync(SubscriptionName)

    public static Task<SubscriberClient> CreateAsync(SubscriptionName subscriptionName)

Creates a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName), using default settings.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `subscriptionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionName` The [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName) to receive messages from. |

| **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.SubscriberClient` | A [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName). |

### CreateAsync(SubscriptionName, ClientCreationSettings, Settings)

    [Obsolete("Use SubscriberClient.Create(SubscriptionName) to use the default settings, or SubscriberClientBuilder for customization.")]
    public static Task<SubscriberClient> CreateAsync(SubscriptionName subscriptionName, SubscriberClient.ClientCreationSettings clientCreationSettings = null, SubscriberClient.Settings settings = null)

Create a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName).
The default `settings` and `clientCreationSettings` are suitable for machines with
high network bandwidth (e.g. Google Compute Engine instances). If running with more limited network bandwidth, some
settings may need changing; especially [AckDeadline](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings#Google_Cloud_PubSub_V1_SubscriberClient_Settings_AckDeadline).
By default this method generates a gRPC channel per CPU core; if using a high-core-count machine and using many
clients concurrently then this may need reducing; use the setting [ClientCount](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.ClientCreationSettings#Google_Cloud_PubSub_V1_SubscriberClient_ClientCreationSettings_ClientCount).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `subscriptionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionName` The [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName) to receive messages from. |
| `clientCreationSettings` | `https://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.ClientCreationSettings` Optional. [SubscriberClient.ClientCreationSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.ClientCreationSettings) specifying how to create [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient)s. |
| `settings` | `https://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.Settings` Optional. [SubscriberClient.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings) for creating a [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient). |

| **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.SubscriberClient` | A [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance associated with the specified [SubscriptionName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_SubscriptionName). |

### DisposeAsync()

    public virtual ValueTask DisposeAsync()

Disposes this [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) asynchronously.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask` |   |

**Remarks** This method asynchronously waits for the time interval as specified in the [DisposeTimeout](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings#Google_Cloud_PubSub_V1_SubscriberClient_Settings_DisposeTimeout)
for the [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) to acknowledge the handled messages. If the clean shutdown is not
complete after this time, it is aborted; this may leave some handled messages un-acknowledged.
The time interval can be customized by setting the [DisposeTimeout](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.Settings#Google_Cloud_PubSub_V1_SubscriberClient_Settings_DisposeTimeout).

### StartAsync(SubscriptionHandler)

    public virtual Task StartAsync(SubscriptionHandler handler)

Starts receiving messages. The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when either [StopAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_StopAsync_System_Threading_CancellationToken_) is called
or if an unrecoverable fault occurs. See [StopAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_StopAsync_System_Threading_CancellationToken_) for more details.
This method cannot be called more than once per [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriptionHandler` The handler that is passed all received messages and acknowledgement results. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) that completes when the subscriber is stopped, or if an unrecoverable error occurs. |

### StartAsync(Func\<PubsubMessage, CancellationToken, Task\<Reply\>\>)

    public virtual Task StartAsync(Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>> handlerAsync)

Starts receiving messages. The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when either [StopAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_StopAsync_System_Threading_CancellationToken_) is called
or if an unrecoverable fault occurs. See [StopAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient#Google_Cloud_PubSub_V1_SubscriberClient_StopAsync_System_Threading_CancellationToken_) for more details.
This method cannot be called more than once per [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient) instance.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handlerAsync` | `https://learn.microsoft.com/dotnet/api/system.func-3https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessagehttps://learn.microsoft.com/dotnet/api/system.threading.cancellationtokenhttps://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` 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). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) that completes when the subscriber is stopped, or if an unrecoverable error occurs. |

### StopAsync(ShutdownOptions, CancellationToken)

    public virtual Task StopAsync(SubscriberClient.ShutdownOptions shutdownOptions, CancellationToken cancellationToken = default)

Stops this [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient).
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when the shutdown is finished according to the
`shutdownOptions` or when the `cancellationToken` is cancelled.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) faults if an unrecoverable error occurs in the underlying service.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) cancels if `cancellationToken` is cancelled.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `shutdownOptions` | `https://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.ShutdownOptions` The [SubscriberClient.ShutdownOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient.ShutdownOptions) to use for shutdown. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancel this [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to immediately abort handlers and acknowledgement. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) that completes when the subscriber is stopped, or if an unrecoverable error occurs. |

### StopAsync(CancellationToken)

    [Obsolete("Use StopAsync(ShutdownOptions, CancellationToken) instead.")]
    public virtual Task StopAsync(CancellationToken hardStopToken)

Stop this [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient). Cancelling `hardStopToken` aborts the
clean stop process, and may leave some handled messages un-acknowledged.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when all handled messages have been acknowledged.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) faults if there is an unrecoverable error with the underlying service.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) cancels if `hardStopToken` is cancelled.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `hardStopToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancel this [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken) to abort handlers and acknowledgement. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) that completes when all handled messages have been acknowledged; faults on unrecoverable service errors; or cancels if `hardStopToken` is cancelled. |

### StopAsync(TimeSpan)

    [Obsolete("Use StopAsync(ShutdownOptions, CancellationToken) instead.")]
    public virtual Task StopAsync(TimeSpan timeout)

Stop this [SubscriberClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.SubscriberClient). If `timeout` expires, the
clean stop process will be aborted, and may leave some handled messages un-acknowledged.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when all handled messages have been acknowledged.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) faults if there is an unrecoverable error with the underlying service.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) cancels if `timeout` expires.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://learn.microsoft.com/dotnet/api/system.timespan` After this period, abort handling and acknowledging messages. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) that completes when all handled messages have been acknowledged; faults on unrecoverable service errors; or cancels if `timeout` expires. |