AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Transactional Session with Azure Table Persistence

Target Version:
NServiceBus 7.x
Standard support for version 7.x of NServiceBus has expired. For more information see our Support Policy.

In order to use the transactional session feature with Azure Table Persistence, add a reference to the NServiceBus.Persistence.AzureTable.TransactionalSession NuGet package.

Configuration

To enable the transactional session feature:

var persistence = config.UsePersistence<AzureTablePersistence>();
persistence.EnableTransactionalSession();

Opening a session

To open an Azure Storage Persistence transactional session:

using var childBuilder = builder.CreateChildBuilder();
var session = childBuilder.Build<ITransactionalSession>();
await session.Open(
        new AzureTableOpenSessionOptions(
            new TableEntityPartitionKey("MyPartitionKey")));

// use the session

await session.Commit();

Configuring the table

The name of the destination table can be specified when opening the session:

using var childBuilder = builder.CreateChildBuilder();
var session = childBuilder.Build<ITransactionalSession>();
await session.Open(
        new AzureTableOpenSessionOptions(
            new TableEntityPartitionKey("MyPartitionKey"),
            new TableInformation("MyTable")));

// use the session

await session.Commit();

Transaction usage

Message and database operations made via the transactional session are committed together once the session is committed:

await session.Open(
        new AzureTableOpenSessionOptions(
            new TableEntityPartitionKey("MyPartitionKey")));

// add messages to the transaction:
await session.Send(new MyMessage());

// access the database:
var azureTableSession = session.SynchronizedStorageSession.AzureTablePersistenceSession();

await session.Commit();

See the Azure table persistence transactions documentation for further details about using the transaction.

Related Articles