public abstract class SubscriberClient
A PubSub subscriber that is associated with a specific SubscriptionName.
Inheritance
System.Object > SubscriberClientNamespace
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 |
System.TimeSpan |
DefaultAckExtensionWindow
public static TimeSpan DefaultAckExtensionWindow { get; }
The default message ACKnowledgement extension window of 15 seconds.
Property Value | |
---|---|
Type | Description |
System.TimeSpan |
DefaultFlowControlSettings
public static FlowControlSettings DefaultFlowControlSettings { get; }
Default Google.Api.Gax.FlowControlSettings for SubscriberClient. Allows 1,000 outstanding messages; and 100Mb outstanding bytes.
Property Value | |
---|---|
Type | Description |
Google.Api.Gax.FlowControlSettings | Default Google.Api.Gax.FlowControlSettings for SubscriberClient. |
DefaultMaxTotalAckExtension
public static TimeSpan DefaultMaxTotalAckExtension { get; }
The default maximum total ACKnowledgement extension of 60 minutes.
Property Value | |
---|---|
Type | Description |
System.TimeSpan |
MaximumAckDeadline
public static TimeSpan MaximumAckDeadline { get; }
The service-defined maximum message ACKnowledgement deadline of 10 minutes.
Property Value | |
---|---|
Type | Description |
System.TimeSpan |
MinimumAckDeadline
public static TimeSpan MinimumAckDeadline { get; }
The service-defined minimum message ACKnowledgement deadline of 10 seconds.
Property Value | |
---|---|
Type | Description |
System.TimeSpan |
MinimumAckExtensionWindow
public static TimeSpan MinimumAckExtensionWindow { get; }
The minimum message ACKnowledgement extension window of 50 milliseconds.
Property Value | |
---|---|
Type | Description |
System.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 |
System.TimeSpan |
SubscriptionName
public virtual SubscriptionName SubscriptionName { get; }
The associated SubscriptionName.
Property Value | |
---|---|
Type | Description |
SubscriptionName |
Methods
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.
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 |
System.Threading.Tasks.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 System.Threading.Tasks.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 | System.Func<PubsubMessage, System.Threading.CancellationToken, System.Threading.Tasks.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 |
System.Threading.Tasks.Task | A System.Threading.Tasks.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 System.Threading.Tasks.Task completes when all handled messages have been ACKnowledged.
The returned System.Threading.Tasks.Task faults if there is an unrecoverable error with the underlying service.
The returned System.Threading.Tasks.Task cancels if hardStopToken
is cancelled.
Parameter | |
---|---|
Name | Description |
hardStopToken | System.Threading.CancellationToken Cancel this System.Threading.CancellationToken to abort handlers and ACKnowledgement. |
Returns | |
---|---|
Type | Description |
System.Threading.Tasks.Task | A System.Threading.Tasks.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 System.Threading.Tasks.Task completes when all handled messages have been ACKnowledged.
The returned System.Threading.Tasks.Task faults if there is an unrecoverable error with the underlying service.
The returned System.Threading.Tasks.Task cancels if timeout
expires.
Parameter | |
---|---|
Name | Description |
timeout | System.TimeSpan After this period, abort handling and ACKnowledging messages. |
Returns | |
---|---|
Type | Description |
System.Threading.Tasks.Task | A System.Threading.Tasks.Task that completes when all handled messages have been ACKnowledged;
faults on unrecoverable service errors; or cancels if |