Table of Contents

Interface IMessageSession

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

Describes a Session object. IMessageSession can be used to perform operations on sessions.

public interface IMessageSession : IMessageReceiver, IReceiverClient, IClientEntity
Inherited Members

Remarks

Service Bus Sessions, also called 'Groups' in the AMQP 1.0 protocol, are unbounded sequences of related messages. ServiceBus guarantees ordering of messages in a session.

Any sender can create a session when submitting messages into a Topic or Queue by setting the SessionId property on Message to some application defined unique identifier. At the AMQP 1.0 protocol level, this value maps to the group-id property.

Sessions come into existence when there is at least one message with the session's SessionId in the Queue or Topic subscription. Once a Session exists, there is no defined moment or gesture for when the session expires or disappears.

Properties

LockedUntilUtc

Gets the time that the session identified by SessionId is locked until for this client.

DateTime LockedUntilUtc { get; }

Property Value

DateTime

SessionId

Gets the SessionId.

string SessionId { get; }

Property Value

string

Methods

GetStateAsync()

Gets the session state.

Task<byte[]> GetStateAsync()

Returns

Task<byte[]>

The session state as byte array.

RenewSessionLockAsync()

Renews the lock on the session specified by the SessionId. The lock will be renewed based on the setting specified on the entity.

Task RenewSessionLockAsync()

Returns

Task

Remarks

When you accept a session, the session is locked for this client instance by the service for a duration as specified during the Queue/Subscription creation. If processing of the session requires longer than this duration, the session-lock needs to be renewed. For each renewal, it resets the time the session is locked by the LockDuration set on the Entity.

Renewal of session renews all the messages in the session as well. Each individual message need not be renewed.

SetStateAsync(byte[])

Set a custom state on the session which can be later retrieved using GetStateAsync()

Task SetStateAsync(byte[] sessionState)

Parameters

sessionState byte[]

A byte array of session state

Returns

Task

Remarks

This state is stored on Service Bus forever unless you set an empty state on it.