Sqlite Outbox
The SQLite Outbox provides a message store for the Transactional Outbox pattern using a SQLite database. This ensures that messages are saved within the same transaction as your business logic and published to a message broker later.
NuGet Packages
To use the SQLite Outbox, you need to install the following packages from NuGet. If you are using Entity Framework Core, you will also need the EF Core integration package.
Install-Package Paramore.Brighter.Sqlite
Install-Package Paramore.Brighter.Outbox.SqliteFor Entity Framework Core support:
Install-Package Paramore.Brighter.Sqlite.EntityFrameworkCoreDatabase Table Schema
The SQLite Outbox requires a specific table in your database to store messages before they are dispatched. You can generate the necessary SQL Data Definition Language (DDL) script to create this table using the SqliteOutboxBuilder helper class.
Note: You are responsible for creating and maintaining this table. This includes tasks such as adding indexes to optimize query performance and managing schema migrations when updating to new versions of Brighter that may require additional columns.
Generating the DDL
The SqliteOutboxBuilder.GetDDL() method creates the SQL script for you. You can execute this script against your database to create the outbox table.
// The table name can be whatever you choose.
string tableName = "Outbox";
// The DDL for a table that stores the message body as TEXT
string ddl = SqliteOutboxBuilder.GetDDL(tableName);
// The DDL for a table that stores the message body as BLOB
// Useful if your message body is binary
string binaryDdl = SqliteOutboxBuilder.GetDDL(tableName, hasBinaryMessagePayload: true);Example SQL Script
Running SqliteOutboxBuilder.GetDDL("Outbox") will generate the following SQL script:
Configuration
To configure the SQLite Outbox, you need to provide an outbox implementation in the AddProducers configuration when setting up Brighter.
1. Provide Database Configuration
First, define the configuration for your SQLite database connection. We recommend retrieving the connection string from your application's configuration (e.g., appsettings.json) rather than hardcoding it.
2. Register the Outbox
Next, in your ConfigureServices method or Program.cs, add the outbox configuration when calling AddBrighter. You need to specify the Outbox, ConnectionProvider, and TransactionProvider.
The TransactionProvider depends on how you manage your database transactions.
Use
SqliteUnitOfWorkfor ADO.NET-based transaction management.Use
SqliteEntityFrameworkConnectionProvider<T>if you are using Entity Framework Core, whereTis yourDbContext.
Example with Entity Framework Core
For more detailed information on integrating with Entity Framework Core, please see the EF Core Outbox documentation.
Here is a complete example of configuring the SQLite Outbox with EF Core.
Last updated
Was this helpful?
