SubscriptionClient Class

Definition

SubscriptionClient can be used for all basic interactions with a Service Bus Subscription.

public class SubscriptionClient : Microsoft.Azure.ServiceBus.ClientEntity, Microsoft.Azure.ServiceBus.ISubscriptionClient
type SubscriptionClient = class
    inherit ClientEntity
    interface ISubscriptionClient
    interface IReceiverClient
    interface IClientEntity
Public Class SubscriptionClient
Inherits ClientEntity
Implements ISubscriptionClient
Inheritance
System.Object
SubscriptionClient
Implements

Examples

Create a new SubscriptionClient

ISubscriptionClient subscriptionClient = new SubscriptionClient(
    namespaceConnectionString,
    topicName,
    subscriptionName,
    ReceiveMode.PeekLock,
    RetryExponential);

Register a message handler which will be invoked every time a message is received.

subscriptionClient.RegisterMessageHandler(
       async (message, token) =>
       {
           // Process the message
           Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");

           // Complete the message so that it is not received again.
           // This can be done only if the subscriptionClient is opened in ReceiveMode.PeekLock mode.
           await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
       },
       async (exceptionEvent) =>
       {
           // Process the exception
           Console.WriteLine("Exception = " + exceptionEvent.Exception);
           return Task.CompletedTask;
       });

Remarks

It uses AMQP protocol for communicating with service bus. Use MessageReceiver for advanced set of functionality.

Constructors

SubscriptionClient(ServiceBusConnectionStringBuilder, String, ReceiveMode, RetryPolicy)

Instantiates a new SubscriptionClient to perform operations on a subscription.

SubscriptionClient(String, String, String, ITokenProvider, TransportType, ReceiveMode, RetryPolicy)

Creates a new instance of the Subscription client using the specified endpoint, entity path, and token provider.

SubscriptionClient(String, String, String, ReceiveMode, RetryPolicy)

Instantiates a new SubscriptionClient to perform operations on a subscription.

Properties

ClientId

Gets the ID to identify this client. This can be used to correlate logs and exceptions.

(Inherited from ClientEntity)
IsClosedOrClosing

Returns true if the client is closed or closing.

(Inherited from ClientEntity)
OperationTimeout

Duration after which individual operations will timeout.

Path

Gets the formatted path of the subscription client.

PrefetchCount

Prefetch speeds up the message flow by aiming to have a message readily available for local retrieval when and before the application asks for one using Receive. Setting a non-zero value prefetches PrefetchCount number of messages. Setting the value to zero turns prefetch off. Defaults to 0.

ReceiveMode

Gets the ReceiveMode for the SubscriptionClient.

RegisteredPlugins

Gets a list of currently registered plugins for this SubscriptionClient.

RetryPolicy

Gets the RetryPolicy defined on the client.

(Inherited from ClientEntity)
SubscriptionName

Gets the name of the subscription.

TopicPath

Gets the path of the corresponding topic.

Methods

AbandonAsync(String, IDictionary<String,Object>)

Abandons a Message using a lock token. This will make the message available again for processing.

AddRuleAsync(RuleDescription)

Adds a rule to the current subscription to filter the messages reaching from topic to the subscription.

AddRuleAsync(String, Filter)

Adds a rule to the current subscription to filter the messages reaching from topic to the subscription.

CloseAsync()

Closes the Client. Closes the connections opened by it.

(Inherited from ClientEntity)
CompleteAsync(String)

Completes a Message using its lock token. This will delete the message from the subscription.

DeadLetterAsync(String)

Moves a message to the deadletter sub-queue.

DeadLetterAsync(String, IDictionary<String,Object>)

Moves a message to the deadletter sub-queue.

DeadLetterAsync(String, String, String)

Moves a message to the deadletter sub-queue.

GetRulesAsync()

Get all rules associated with the subscription.

OnClosingAsync()
RegisterMessageHandler(Func<Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>)

Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(System.Func`3) is awaited on every time a new message is received by the receiver.

RegisterMessageHandler(Func<Message,CancellationToken,Task>, MessageHandlerOptions)

Receive messages continuously from the entity. Registers a message handler and begins a new thread to receive messages. This handler(System.Func`3) is awaited on every time a new message is received by the receiver.

RegisterPlugin(ServiceBusPlugin)

Registers a ServiceBusPlugin to be used for receiving messages from Service Bus.

RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, Func<ExceptionReceivedEventArgs,Task>)

Receive session messages continuously from the queue. Registers a message handler and begins a new thread to receive session-messages. This handler(System.Func`4) is awaited on every time a new message is received by the subscription client.

RegisterSessionHandler(Func<IMessageSession,Message,CancellationToken,Task>, SessionHandlerOptions)

Receive session messages continuously from the queue. Registers a message handler and begins a new thread to receive session-messages. This handler(System.Func`4) is awaited on every time a new message is received by the subscription client.

RemoveRuleAsync(String)

Removes the rule on the subscription identified by ruleName.

ThrowIfClosed()

Throw an OperationCanceledException if the object is Closing.

(Inherited from ClientEntity)
UnregisterPlugin(String)

Unregisters a ServiceBusPlugin.

Applies to