public abstract class SubscriberClient
A PubSub subscriber that is associated with a specific SubscriptionName.
Derived Types
Namespace
Google.Cloud.PubSub.V1Assembly
Google.Cloud.PubSub.V1.dll
Remarks
To receive messages, the StartAsync(Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>>) method must be called, with a suitable message handler.
The message handler 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.
Properties
DefaultAckDeadline
public static TimeSpan DefaultAckDeadline { get; }
The default message ACKnowledgement deadline of 60 seconds.
Property Value | |
---|---|
Type | Description |
TimeSpan |
DefaultAckExtensionWindow
public static TimeSpan DefaultAckExtensionWindow { get; }
The default message ACKnowledgement extension window of 15 seconds.
Property Value | |
---|---|
Type | Description |
TimeSpan |
DefaultFlowControlSettings
public static FlowControlSettings DefaultFlowControlSettings { get; }
Default FlowControlSettings for SubscriberClient. Allows 1,000 outstanding messages; and 100Mb outstanding bytes.
Property Value | |
---|---|
Type | Description |
FlowControlSettings | Default FlowControlSettings for SubscriberClient. |
DefaultMaxTotalAckExtension
public static TimeSpan DefaultMaxTotalAckExtension { get; }
The default maximum total ACKnowledgement extension of 60 minutes.
Property Value | |
---|---|
Type | Description |
TimeSpan |
MaximumAckDeadline
public static TimeSpan MaximumAckDeadline { get; }
The service-defined maximum message ACKnowledgement deadline of 10 minutes.
Property Value | |
---|---|
Type | Description |
TimeSpan |
MinimumAckDeadline
public static TimeSpan MinimumAckDeadline { get; }
The service-defined minimum message ACKnowledgement deadline of 10 seconds.
Property Value | |
---|---|
Type | Description |
TimeSpan |
MinimumAckExtensionWindow
public static TimeSpan MinimumAckExtensionWindow { get; }
The minimum message ACKnowledgement extension window of 50 milliseconds.
Property Value | |
---|---|
Type | Description |
TimeSpan |
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 |
TimeSpan |
SubscriptionName
public virtual SubscriptionName SubscriptionName { get; }
The associated SubscriptionName.
Property Value | |
---|---|
Type | Description |
SubscriptionName |
Methods
Create(SubscriptionName, SubscriberClient.ClientCreationSettings, SubscriberClient.Settings)
public static SubscriberClient Create(SubscriptionName subscriptionName, SubscriberClient.ClientCreationSettings clientCreationSettings = null, SubscriberClient.Settings settings = null)
Create a SubscriberClient instance associated with the specified 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.
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.
Parameters | |
---|---|
Name | Description |
subscriptionName | SubscriptionName The SubscriptionName to receive messages from. |
clientCreationSettings | SubscriberClient.ClientCreationSettings Optional. SubscriberClient.ClientCreationSettings specifying how to create SubscriberClients. |
settings | SubscriberClient.Settings Optional. SubscriberClient.Settings for creating a SubscriberClient. |
Returns | |
---|---|
Type | Description |
SubscriberClient | A SubscriberClient instance associated with the specified SubscriptionName. |
CreateAsync(SubscriptionName, SubscriberClient.ClientCreationSettings, SubscriberClient.Settings)
public static Task<SubscriberClient> CreateAsync(SubscriptionName subscriptionName, SubscriberClient.ClientCreationSettings clientCreationSettings = null, SubscriberClient.Settings settings = null)
Create a SubscriberClient instance associated with the specified 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.
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.
Parameters | |
---|---|
Name | Description |
subscriptionName | SubscriptionName The SubscriptionName to receive messages from. |
clientCreationSettings | SubscriberClient.ClientCreationSettings Optional. SubscriberClient.ClientCreationSettings specifying how to create SubscriberClients. |
settings | SubscriberClient.Settings Optional. SubscriberClient.Settings for creating a SubscriberClient. |
Returns | |
---|---|
Type | Description |
Task<SubscriberClient> | A SubscriberClient instance associated with the specified SubscriptionName. |
StartAsync(Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>>)
public virtual 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 | |
---|---|
Name | Description |
handlerAsync | Func<PubsubMessage, CancellationToken, Task<SubscriberClient.Reply>> 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 | |
---|---|
Type | Description |
Task | A Task that completes when the subscriber is stopped, or if an unrecoverable error occurs. |
StopAsync(CancellationToken)
public virtual 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 | |
---|---|
Name | Description |
hardStopToken | CancellationToken Cancel this CancellationToken to abort handlers and ACKnowledgement. |
Returns | |
---|---|
Type | Description |
Task | A Task that completes when all handled messages have been ACKnowledged;
faults on unrecoverable service errors; or cancels if |
StopAsync(TimeSpan)
public virtual Task StopAsync(TimeSpan timeout)
Stop this SubscriberClient. If timeout
expires, the
clean stop process will be aborted, 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 timeout
expires.
Parameter | |
---|---|
Name | Description |
timeout | TimeSpan After this period, abort handling and ACKnowledging messages. |
Returns | |
---|---|
Type | Description |
Task | A Task that completes when all handled messages have been ACKnowledged;
faults on unrecoverable service errors; or cancels if |