# Cloud Pub/Sub v1 API - Class PublisherClientImpl (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 sealed class PublisherClientImpl : PublisherClient, IAsyncDisposable

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

Implementation of PubSub publisher that is associated with a specific [TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl#Google_Cloud_PubSub_V1_PublisherClientImpl_TopicName).

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) \> PublisherClientImpl

## Implements

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

## Inherited Members

[PublisherClient.DefaultBatchingSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_DefaultBatchingSettings) [PublisherClient.ApiMaxBatchingSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_ApiMaxBatchingSettings) [PublisherClient.DefaultDisposeTimeout](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_DefaultDisposeTimeout) [PublisherClient.DefaultCompressionBytesThreshold](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_DefaultCompressionBytesThreshold) [PublisherClient.Create(TopicName)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_Create_Google_Cloud_PubSub_V1_TopicName_) [PublisherClient.CreateAsync(TopicName)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_CreateAsync_Google_Cloud_PubSub_V1_TopicName_) [PublisherClient.Create(TopicName, PublisherClient.ClientCreationSettings, PublisherClient.Settings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_Create_Google_Cloud_PubSub_V1_TopicName_Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_Google_Cloud_PubSub_V1_PublisherClient_Settings_) [PublisherClient.CreateAsync(TopicName, PublisherClient.ClientCreationSettings, PublisherClient.Settings)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_CreateAsync_Google_Cloud_PubSub_V1_TopicName_Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_Google_Cloud_PubSub_V1_PublisherClient_Settings_) [PublisherClient.PublishAsync(string, string, Encoding)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_String_System_String_System_Text_Encoding_) [PublisherClient.PublishAsync(string, Encoding)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_String_System_Text_Encoding_) [PublisherClient.PublishAsync(string, IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_String_Google_Protobuf_IMessage_) [PublisherClient.PublishAsync(IMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_Google_Protobuf_IMessage_) [PublisherClient.PublishAsync(string, ByteString)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_String_Google_Protobuf_ByteString_) [PublisherClient.PublishAsync(ByteString)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_Google_Protobuf_ByteString_) [PublisherClient.PublishAsync(string, byte\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_String_System_Byte___) [PublisherClient.PublishAsync(byte\[\])](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_System_Byte___) [PublisherClient.ShutdownAsync(TimeSpan)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_ShutdownAsync_System_TimeSpan_) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [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

## Constructors

### PublisherClientImpl(TopicName, IEnumerable\<PublisherServiceApiClient\>, Settings, Func\<Task\>)

    public PublisherClientImpl(TopicName topicName, IEnumerable<PublisherServiceApiClient> clients, PublisherClient.Settings settings, Func<Task> shutdown)

Instantiate a [PublisherClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl) associated with the specified [TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl#Google_Cloud_PubSub_V1_PublisherClientImpl_TopicName).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `topicName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.TopicName` The [TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl#Google_Cloud_PubSub_V1_PublisherClientImpl_TopicName) to publish messages to. |
| `clients` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherServiceApiClient` The [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient)s to use. |
| `settings` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClienthttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.Settings` [PublisherClient.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.Settings) to use in this [PublisherClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl). |
| `shutdown` | `https://learn.microsoft.com/dotnet/api/system.func-1https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` Function to call on this [PublisherClientImpl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClientImpl) shutdown. |

## Properties

### TopicName

    public override TopicName TopicName { get; }

The associated [TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName).

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

**Overrides** [PublisherClient.TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName)

## Methods

### DisposeAsync()

    public override ValueTask DisposeAsync()

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

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

**Overrides** [PublisherClient.DisposeAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_DisposeAsync) **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.PublisherClient.Settings#Google_Cloud_PubSub_V1_PublisherClient_Settings_DisposeTimeout)
for the [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) to send any pending messages. If the clean shutdown is not
complete after this time, it is aborted; this may leave some locally queued messages unsent.
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.PublisherClient.Settings#Google_Cloud_PubSub_V1_PublisherClient_Settings_DisposeTimeout).

### PublishAsync(PubsubMessage)

    public override Task<string> PublishAsync(PubsubMessage message)

Publish a message to the topic specified in [TopicName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage` The [PubsubMessage](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PubsubMessage) to publish. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.string` | A task which completes once the message has been published. The task [Result](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1.result) contains the message ID. |

**Overrides** [PublisherClient.PublishAsync(PubsubMessage)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_PublishAsync_Google_Cloud_PubSub_V1_PubsubMessage_)

### ResumePublish(string)

    public override void ResumePublish(string orderingKey)

Re-enable publishing the the given ordering key, after an error has caused the ordering key to be disabled.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `orderingKey` | `https://learn.microsoft.com/dotnet/api/system.string` The ordering key to re-enable. |

**Overrides** [PublisherClient.ResumePublish(string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_ResumePublish_System_String_)

### ShutdownAsync(CancellationToken)

    public override Task ShutdownAsync(CancellationToken hardStopToken)

Shutdown this [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient). Cancelling `hardStopToken` aborts the
clean shutdown process, and may leave some locally queued messages unsent.
The returned [Task](https://learn.microsoft.com/dotnet/api/system.threading.tasks.task) completes when all queued messages have been published.
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 publishing queued 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 queued messages have been published; or cancels if `hardStopToken` is cancelled. |

**Overrides** [PublisherClient.ShutdownAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_ShutdownAsync_System_Threading_CancellationToken_)