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

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

A 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.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName).

## Inheritance

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

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

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

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

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

## Properties

### ApiMaxBatchingSettings

    public static BatchingSettings ApiMaxBatchingSettings { get; }

The absolute maximum [BatchingSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html) supported by the service.
Maximum values are:
[ElementCountThreshold](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html#Google_Api_Gax_BatchingSettings_ElementCountThreshold) = 1,000;
[ByteCountThreshold](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html#Google_Api_Gax_BatchingSettings_ByteCountThreshold) = 10,000,000;

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html` |   |

### DefaultBatchingSettings

    public static BatchingSettings DefaultBatchingSettings { get; }

Default [BatchingSettings](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html) for [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient).
Default values are:
[ElementCountThreshold](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html#Google_Api_Gax_BatchingSettings_ElementCountThreshold) = 100;
[ByteCountThreshold](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html#Google_Api_Gax_BatchingSettings_ByteCountThreshold) = 1,000,000;
[DelayThreshold](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html#Google_Api_Gax_BatchingSettings_DelayThreshold) = 10 milliseconds;

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.BatchingSettings.html` |   |

### DefaultCompressionBytesThreshold

    public static long DefaultCompressionBytesThreshold { get; }

The default [CompressionBytesThreshold](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_CompressionBytesThreshold) of 240 bytes for the publisher message compression.

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

### 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.PublisherClient.Settings#Google_Cloud_PubSub_V1_PublisherClient_Settings_DisposeTimeout) of 5 seconds for the [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient).

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

### TopicName

    public virtual 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` |   |

## Methods

### Create(TopicName)

    public static PublisherClient Create(TopicName topicName)

Create a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) instance associated with the specified [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), using default settings.

| **Parameter** ||
|---|---|
| **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.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName) to publish messages to. Must not be null. |

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

### Create(TopicName, ClientCreationSettings, Settings)

    [Obsolete("Use PublisherClient.Create(TopicName) to use the default settings, or PublisherClientBuilder for customization.")]
    public static PublisherClient Create(TopicName topicName, PublisherClient.ClientCreationSettings clientCreationSettings = null, PublisherClient.Settings settings = null)

Create a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) instance associated with the specified [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).
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
[PublisherServiceApiSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.ClientCreationSettings#Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_PublisherServiceApiSettings).[PublishSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherServiceApiSettings#Google_Cloud_PubSub_V1_PublisherServiceApiSettings_PublishSettings).[Retry](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html#Google_Api_Gax_Grpc_CallSettings_Retry).
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.PublisherClient.ClientCreationSettings#Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_ClientCount).

| **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.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName) to publish messages to. Must not be null. |
| `clientCreationSettings` | `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.ClientCreationSettings` Optional. [PublisherClient.ClientCreationSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.ClientCreationSettings) specifying how to create [PublisherServiceApiClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherServiceApiClient)s. |
| `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` Optional. [PublisherClient.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.Settings) for creating a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient). |

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

### CreateAsync(TopicName)

    public static Task<PublisherClient> CreateAsync(TopicName topicName)

Creates a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) instance associated with the specified [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), using default settings.

| **Parameter** ||
|---|---|
| **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.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName) to publish messages to. Must not be null. |

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

### CreateAsync(TopicName, ClientCreationSettings, Settings)

    [Obsolete("Use PublisherClient.CreateAsync(TopicName) to use the default settings, or PublisherClientBuilder for customization.")]
    public static Task<PublisherClient> CreateAsync(TopicName topicName, PublisherClient.ClientCreationSettings clientCreationSettings = null, PublisherClient.Settings settings = null)

Create a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient) instance associated with the specified [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).
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
[PublisherServiceApiSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.ClientCreationSettings#Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_PublisherServiceApiSettings).[PublishSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherServiceApiSettings#Google_Cloud_PubSub_V1_PublisherServiceApiSettings_PublishSettings).[Retry](https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html#Google_Api_Gax_Grpc_CallSettings_Retry).
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.PublisherClient.ClientCreationSettings#Google_Cloud_PubSub_V1_PublisherClient_ClientCreationSettings_ClientCount).

| **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.PublisherClient#Google_Cloud_PubSub_V1_PublisherClient_TopicName) to publish messages to. Must not be null. |
| `clientCreationSettings` | `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.ClientCreationSettings` Optional. [PublisherClient.ClientCreationSettings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.ClientCreationSettings) specifying how to create [PublisherServiceApiClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherServiceApiClient)s. |
| `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` Optional. [PublisherClient.Settings](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient.Settings) for creating a [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient). |

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

### DisposeAsync()

    public virtual 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` |   |

**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 virtual 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. |

### PublishAsync(ByteString)

    public virtual Task<string> PublishAsync(ByteString 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://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The [ByteString](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html) 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. |

### PublishAsync(IMessage)

    public virtual Task<string> PublishAsync(IMessage 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://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html` The message 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. |

### PublishAsync(byte\[\])

    public virtual Task<string> PublishAsync(byte[] 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` | `System.Byte` The message 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. |

### PublishAsync(string, ByteString)

    public virtual Task<string> PublishAsync(string orderingKey, ByteString 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).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `orderingKey` | `https://learn.microsoft.com/dotnet/api/system.string` The ordering key to use for this message. |
| `message` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The [ByteString](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html) 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. |

### PublishAsync(string, IMessage)

    public virtual Task<string> PublishAsync(string orderingKey, IMessage 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).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `orderingKey` | `https://learn.microsoft.com/dotnet/api/system.string` The ordering key to use for this message. |
| `message` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html` The message 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. |

### PublishAsync(string, byte\[\])

    public virtual Task<string> PublishAsync(string orderingKey, byte[] 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).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `orderingKey` | `https://learn.microsoft.com/dotnet/api/system.string` The ordering key to use for this message. |
| `message` | `System.Byte` The message 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. |

### PublishAsync(string, string, Encoding)

    public virtual Task<string> PublishAsync(string orderingKey, string message, Encoding encoding = null)

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `orderingKey` | `https://learn.microsoft.com/dotnet/api/system.string` The ordering key to use for this message. |
| `message` | `https://learn.microsoft.com/dotnet/api/system.string` The string to publish. |
| `encoding` | `https://learn.microsoft.com/dotnet/api/system.text.encoding` The encoding for string to byte conversion. If `null`, defaults to [UTF8](https://learn.microsoft.com/dotnet/api/system.text.encoding.utf8). |

| **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. |

### PublishAsync(string, Encoding)

    public virtual Task<string> PublishAsync(string message, Encoding encoding = null)

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

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://learn.microsoft.com/dotnet/api/system.string` The string to publish. |
| `encoding` | `https://learn.microsoft.com/dotnet/api/system.text.encoding` The encoding for string to byte conversion. If `null`, defaults to [UTF8](https://learn.microsoft.com/dotnet/api/system.text.encoding.utf8). |

| **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. |

### ResumePublish(string)

    public virtual 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. |

### ShutdownAsync(CancellationToken)

    public virtual 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. |

### ShutdownAsync(TimeSpan)

    public virtual Task ShutdownAsync(TimeSpan timeout)

Shutdown this [PublisherClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.PubSub.V1/latest/Google.Cloud.PubSub.V1.PublisherClient). If `timeout` expires, the clean shutdown process will
abort; leaving 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 the `timeout` expires before all messages are published.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `timeout` | `https://learn.microsoft.com/dotnet/api/system.timespan` After this period, 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 `timeout` expires. |