Dynamo Outbox

Usage

The DynamoDb Outbox allows integration between DynamoDb and Brighter's outbox support. The configuration is described in Basic Configuration.

To support transactional messaging when using DynamoDb requires us to use DynamoDb's support for ACID transactions. You should understand best practices for using transactions with DynamoDb.

For this we will need the Outbox package for DynamoDb:

AWS SDK v3 (legacy support):

  • Paramore.Brighter.Outbox.DynamoDB

AWS SDK v4 (recommended for new projects):

  • Paramore.Brighter.Outbox.DynamoDB.V4

Paramore.Brighter.Outbox.DynamoDb (or .V4) will pull in another package:

  • Paramore.Brighter.DynamoDb (or Paramore.Brighter.DynamoDb.V4)

See AWS Configuration for migration guidance between v3 and v4.

As described in Basic Configuration, we configure Brighter to use an outbox with the Use{DB}Outbox method call.

As we want to use DynamoDb with the outbox, we also call: Use{DB}TransactionConnectionProvider so that we can share your transaction scope when persisting messages to the outbox.

public void ConfigureServices(IServiceCollection services)
{
    services.AddBrighter(...)
        .AddProducers(...)
        .UseDynamoDbOutbox(ServiceLifetime.Singleton)
        .UseDynamoDbTransactionConnectionProvider(typeof(DynamoDbUnitOfWork), ServiceLifetime.Scoped)
        .UseOutboxSweeper()

        ...
}

In our handler we take a dependency on Brighter's IAmABoxTransactionConnectionProvider interface and convert it to a DynamoDbUnitofWork. We explicitly start a transaction within the handler on the Database within the Unit of Work.

We call DepositPostAsync within that transaction to write the message to the Outbox. Once the transaction has closed we can call ClearOutboxAsync to immediately clear, or we can rely on the Outbox Sweeper, if we have configured one to clear for us. (There are equivalent synchronous versions of these APIs).x

Last updated

Was this helpful?