Table of Contents

Class SessionClient

Namespace
Microsoft.Azure.ServiceBus
Assembly
Microsoft.Azure.ServiceBus.dll

A session client can be used to accept session objects which can be used to interact with all messages with the same sessionId.

public sealed class SessionClient : ClientEntity, ISessionClient, IClientEntity
Inheritance
SessionClient
Implements
Inherited Members

Examples

To create a new SessionClient

ISessionClient sessionClient = new SessionClient(
    namespaceConnectionString,
    queueName,
    ReceiveMode.PeekLock);

To receive a session object for a given sessionId

IMessageSession session = await sessionClient.AcceptMessageSessionAsync(sessionId);

To receive any session

IMessageSession session = await sessionClient.AcceptMessageSessionAsync();

Remarks

You can accept any session or a given session (identified by SessionId using a session client. Once you accept a session, you can use it as a MessageReceiver which receives only messages having the same session id. See IMessageSession for usage of session object. This uses AMQP protocol to communicate with the service.

Constructors

SessionClient(ServiceBusConnection, string, ReceiveMode, RetryPolicy, int)

Creates a new SessionClient on a given ServiceBusConnection

public SessionClient(ServiceBusConnection serviceBusConnection, string entityPath, ReceiveMode receiveMode, RetryPolicy retryPolicy = null, int prefetchCount = 0)

Parameters

serviceBusConnection ServiceBusConnection

Connection object to the service bus namespace.

entityPath string

The path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the full path.

receiveMode ReceiveMode

The Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.

retryPolicy RetryPolicy

The RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default

prefetchCount int

The Microsoft.Azure.ServiceBus.SessionClient.PrefetchCount that specifies the upper limit of messages the session object will actively receive regardless of whether a receive operation is pending. Defaults to 0.

SessionClient(ServiceBusConnectionStringBuilder, ReceiveMode, RetryPolicy, int)

Creates a new SessionClient from a ServiceBusConnectionStringBuilder

public SessionClient(ServiceBusConnectionStringBuilder connectionStringBuilder, ReceiveMode receiveMode = ReceiveMode.PeekLock, RetryPolicy retryPolicy = null, int prefetchCount = 0)

Parameters

connectionStringBuilder ServiceBusConnectionStringBuilder

The ServiceBusConnectionStringBuilder having entity level connection details.

receiveMode ReceiveMode

The Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.

retryPolicy RetryPolicy

The RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default

prefetchCount int

The Microsoft.Azure.ServiceBus.SessionClient.PrefetchCount that specifies the upper limit of messages the session object will actively receive regardless of whether a receive operation is pending. Defaults to 0.

Remarks

Creates a new connection to the entity, which is used for all the sessions objects accepted using this client.

SessionClient(string, string, ITokenProvider, TransportType, ReceiveMode, RetryPolicy, int)

Creates a new SessionClient from a specified endpoint, entity path, and token provider.

public SessionClient(string endpoint, string entityPath, ITokenProvider tokenProvider, TransportType transportType = TransportType.Amqp, ReceiveMode receiveMode = ReceiveMode.PeekLock, RetryPolicy retryPolicy = null, int prefetchCount = 0)

Parameters

endpoint string

Fully qualified domain name for Service Bus. Most likely, {yournamespace}.servicebus.windows.net

entityPath string

Queue path.

tokenProvider ITokenProvider

Token provider which will generate security tokens for authorization.

transportType TransportType

Transport type.

receiveMode ReceiveMode

Mode of receive of messages. Defaults to Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode.PeekLock.

retryPolicy RetryPolicy

Retry policy for queue operations. Defaults to Default

prefetchCount int

The Microsoft.Azure.ServiceBus.SessionClient.PrefetchCount that specifies the upper limit of messages this receiver will actively receive regardless of whether a receive operation is pending. Defaults to 0.

Remarks

Creates a new connection to the entity, which is opened during the first operation.

SessionClient(string, string, ReceiveMode, RetryPolicy, int)

Creates a new SessionClient from a specified connection string and entity path.

public SessionClient(string connectionString, string entityPath, ReceiveMode receiveMode = ReceiveMode.PeekLock, RetryPolicy retryPolicy = null, int prefetchCount = 0)

Parameters

connectionString string

Namespace connection string used to communicate with Service Bus. Must not contain entity details.

entityPath string

The path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the full path.

receiveMode ReceiveMode

The Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.

retryPolicy RetryPolicy

The RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default

prefetchCount int

The Microsoft.Azure.ServiceBus.SessionClient.PrefetchCount that specifies the upper limit of messages the session object will actively receive regardless of whether a receive operation is pending. Defaults to 0.

Remarks

Creates a new connection to the entity, which is used for all the sessions objects accepted using this client.

Properties

EntityPath

Gets the path of the entity. This is either the name of the queue, or the full path of the subscription.

public string EntityPath { get; }

Property Value

string

OperationTimeout

Duration after which individual operations will timeout.

public override TimeSpan OperationTimeout { get; set; }

Property Value

TimeSpan

Path

Gets the path of the entity. This is either the name of the queue, or the full path of the subscription.

public override string Path { get; }

Property Value

string

RegisteredPlugins

Gets a list of currently registered plugins.

public override IList<ServiceBusPlugin> RegisteredPlugins { get; }

Property Value

IList<ServiceBusPlugin>

ServiceBusConnection

Connection object to the service bus namespace.

public override ServiceBusConnection ServiceBusConnection { get; }

Property Value

ServiceBusConnection

Methods

AcceptMessageSessionAsync()

Gets a session object of any SessionId that can be used to receive messages for that sessionId.

public Task<IMessageSession> AcceptMessageSessionAsync()

Returns

Task<IMessageSession>

Remarks

All plugins registered on SessionClient will be applied to each MessageSession that is accepted. Individual sessions can further register additional plugins.

AcceptMessageSessionAsync(string)

Gets a particular session object identified by sessionId that can be used to receive messages for that sessionId.

public Task<IMessageSession> AcceptMessageSessionAsync(string sessionId)

Parameters

sessionId string

The sessionId present in all its messages.

Returns

Task<IMessageSession>

Remarks

All plugins registered on SessionClient will be applied to each MessageSession that is accepted. Individual sessions can further register additional plugins.

AcceptMessageSessionAsync(string, TimeSpan)

Gets a particular session object identified by sessionId that can be used to receive messages for that sessionId.

public Task<IMessageSession> AcceptMessageSessionAsync(string sessionId, TimeSpan serverWaitTime)

Parameters

sessionId string

The sessionId present in all its messages.

serverWaitTime TimeSpan

Amount of time for which the call should wait to fetch the next session.

Returns

Task<IMessageSession>

Remarks

All plugins registered on SessionClient will be applied to each MessageSession that is accepted. Individual sessions can further register additional plugins.

AcceptMessageSessionAsync(TimeSpan)

Gets a session object of any SessionId that can be used to receive messages for that sessionId.

public Task<IMessageSession> AcceptMessageSessionAsync(TimeSpan serverWaitTime)

Parameters

serverWaitTime TimeSpan

Amount of time for which the call should wait to fetch the next session.

Returns

Task<IMessageSession>

Remarks

All plugins registered on SessionClient will be applied to each MessageSession that is accepted. Individual sessions can further register additional plugins.

OnClosingAsync()

protected override Task OnClosingAsync()

Returns

Task

RegisterPlugin(ServiceBusPlugin)

Registers a ServiceBusPlugin to be used with this receiver.

public override void RegisterPlugin(ServiceBusPlugin serviceBusPlugin)

Parameters

serviceBusPlugin ServiceBusPlugin

The ServiceBusPlugin to register.

UnregisterPlugin(string)

Unregisters a ServiceBusPlugin.

public override void UnregisterPlugin(string serviceBusPluginName)

Parameters

serviceBusPluginName string

The Name of the plugin to be unregistered.

See Also