Cloud Pub/Sub v1 API - Class SubscriberClientImpl (3.5.1)

public sealed class SubscriberClientImpl : SubscriberClient, IAsyncDisposable

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

Implementation of SubscriberClient.

Inheritance

object > SubscriberClient > SubscriberClientImpl

Implements

IAsyncDisposable

Namespace

Google.Cloud.PubSub.V1

Assembly

Google.Cloud.PubSub.V1.dll

Constructors

SubscriberClientImpl(SubscriptionName, IEnumerable<SubscriberServiceApiClient>, Settings, Func<Task>)

public SubscriberClientImpl(SubscriptionName subscriptionName, IEnumerable<SubscriberServiceApiClient> clients, SubscriberClient.Settings settings, Func<Task> shutdown)

Instantiate a SubscriberClientImpl associated with the specified SubscriptionName.

Parameters
NameDescription
subscriptionNameSubscriptionName

The SubscriptionName to receive messages from.

clientsIEnumerableSubscriberServiceApiClient

The SubscriberServiceApiClients to use in a SubscriberClient. For high performance, these should all use distinct ChannelBases.

settingsSubscriberClientSettings

SubscriberClient.Settings for creating a SubscriberClient.

shutdownFuncTask

Function to call on this SubscriberClientImpl shutdown.

Properties

SubscriptionName

public override SubscriptionName SubscriptionName { get; }

The associated SubscriptionName.

Property Value
TypeDescription
SubscriptionName
Overrides

Methods

DisposeAsync()

public override ValueTask DisposeAsync()

Disposes this SubscriberClient asynchronously.

Returns
TypeDescription
ValueTask
Overrides Remarks

This method asynchronously waits for the time interval as specified in the DisposeTimeout for the 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.

StartAsync(SubscriptionHandler)

public override Task StartAsync(SubscriptionHandler handler)

Starts receiving messages. The returned Task completes when either StopAsync(CancellationToken) is called or if an unrecoverable fault occurs. See StopAsync(CancellationToken) for more details. This method cannot be called more than once per SubscriberClient instance.

Parameter
NameDescription
handlerSubscriptionHandler

The handler that is passed all received messages and acknowledgement results.

Returns
TypeDescription
Task

A Task that completes when the subscriber is stopped, or if an unrecoverable error occurs.

Overrides

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

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

Starts receiving messages. The returned Task completes when either StopAsync(CancellationToken) is called or if an unrecoverable fault occurs. See StopAsync(CancellationToken) for more details. This method cannot be called more than once per SubscriberClient instance.

Parameter
NameDescription
handlerAsyncFuncPubsubMessageCancellationTokenTaskSubscriberClientReply

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.

Returns
TypeDescription
Task

A Task that completes when the subscriber is stopped, or if an unrecoverable error occurs.

Overrides

StopAsync(CancellationToken)

public override Task StopAsync(CancellationToken hardStopToken)

Stop this SubscriberClient. Cancelling hardStopToken aborts the clean stop process, and may leave some handled messages un-ACKnowledged. The returned Task completes when all handled messages have been ACKnowledged. The returned Task faults if there is an unrecoverable error with the underlying service. The returned Task cancels if hardStopToken is cancelled.

Parameter
NameDescription
hardStopTokenCancellationToken

Cancel this CancellationToken to abort handlers and ACKnowledgement.

Returns
TypeDescription
Task

A Task that completes when all handled messages have been ACKnowledged; faults on unrecoverable service errors; or cancels if hardStopToken is cancelled.

Overrides