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
ServiceBusConnectionConnection object to the service bus namespace.
entityPath
stringThe path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the full path.
receiveMode
ReceiveModeThe Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default
prefetchCount
intThe 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
ServiceBusConnectionStringBuilderThe ServiceBusConnectionStringBuilder having entity level connection details.
receiveMode
ReceiveModeThe Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default
prefetchCount
intThe 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
stringFully qualified domain name for Service Bus. Most likely, {yournamespace}.servicebus.windows.net
entityPath
stringQueue path.
tokenProvider
ITokenProviderToken provider which will generate security tokens for authorization.
transportType
TransportTypeTransport type.
receiveMode
ReceiveModeMode of receive of messages. Defaults to Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode.PeekLock.
retryPolicy
RetryPolicyRetry policy for queue operations. Defaults to Default
prefetchCount
intThe 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
stringNamespace connection string used to communicate with Service Bus. Must not contain entity details.
entityPath
stringThe path of the entity for this receiver. For Queues this will be the name, but for Subscriptions this will be the full path.
receiveMode
ReceiveModeThe Microsoft.Azure.ServiceBus.SessionClient.ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.
retryPolicy
RetryPolicyThe RetryPolicy that will be used when communicating with ServiceBus. Defaults to Default
prefetchCount
intThe 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
OperationTimeout
Duration after which individual operations will timeout.
public override TimeSpan OperationTimeout { get; set; }
Property Value
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
RegisteredPlugins
Gets a list of currently registered plugins.
public override IList<ServiceBusPlugin> RegisteredPlugins { get; }
Property Value
ServiceBusConnection
Connection object to the service bus namespace.
public override ServiceBusConnection ServiceBusConnection { get; }
Property Value
Methods
AcceptMessageSessionAsync()
Gets a session object of any SessionId that can be used to receive messages for that sessionId.
public Task<IMessageSession> AcceptMessageSessionAsync()
Returns
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
stringThe sessionId present in all its messages.
Returns
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
stringThe sessionId present in all its messages.
serverWaitTime
TimeSpanAmount of time for which the call should wait to fetch the next session.
Returns
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
TimeSpanAmount of time for which the call should wait to fetch the next session.
Returns
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
RegisterPlugin(ServiceBusPlugin)
Registers a ServiceBusPlugin to be used with this receiver.
public override void RegisterPlugin(ServiceBusPlugin serviceBusPlugin)
Parameters
serviceBusPlugin
ServiceBusPluginThe ServiceBusPlugin to register.
UnregisterPlugin(string)
Unregisters a ServiceBusPlugin.
public override void UnregisterPlugin(string serviceBusPluginName)