Getting Started
Architecture
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Transactional Session with DynamoDB Persistence

NuGet Package: NServiceBus.Persistence.DynamoDB.TransactionalSession (2-pre)
Target Version: NServiceBus 9.x
This page targets a pre-release version. Pre-releases are subject to change and samples are not guaranteed to be fully functional.

In order 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())
    .ConfigureAwait(false);

// use the session

await session.Commit()
    .ConfigureAwait(false);

Transaction usage

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

await session.Open(new DynamoOpenSessionOptions())
    .ConfigureAwait(false);

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

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

await session.Commit()
    .ConfigureAwait(false);

See the Cosmos DB persistence transactions documentation for further details about using the transaction.

In order to guarantee atomic consistency across message and database operations, the outbox must be enabled. Otherwise Commit executes database modifications first and then messages are dispatched with best-effort.

Related Articles


Last modified