For the complete documentation index, see llms.txt. This section of documentation is indexed by https://docs.particular.net/nservicebus/llms.txt. Here is the markdown version of this page. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md.

Transactional Session with DynamoDB Persistence

To use the transactional session feature with DynamoDB persistence, add a reference to the NServiceBus.Persistence.DynamoDB.TransactionalSession NuGet package.

Configuration

To enable the transactional session feature:

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

Opening a session

To open a DynamoDB transactional session:

using var childScope = serviceProvider.CreateScope();
var session = childScope.ServiceProvider.GetService<ITransactionalSession>();
await session.Open(new DynamoOpenSessionOptions());

// use the session

await session.Commit();

Transactions usage

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

await session.Open(new DynamoOpenSessionOptions());

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

// access the database:
var dynamoSession = session.SynchronizedStorageSession.DynamoPersistenceSession();

await session.Commit();

For further details about using transactions, see the DynamoDB persistence transactions documentation.

Related Articles