Process managers - rebus-org/Rebus GitHub Wiki
Configuring Rebus to persist sagas (in the literature known as process managers) in a database is fairly straightforward.
Generally, you will
- Include an appropriate persistence NuGet package
- Call an appropriate
.StoreIn(...)
extension method from that package
and then saga instances will be stored there in a way that allows for rich modeling in sagas, while still making as much sense for the given persistence technology as possible.
Example with Microsoft SQL Server
With Microsoft SQL Server you will probably
Install-Package Rebus.SqlServer -ProjectName <your-project>
and then do something like this when you configure Rebus:
Configure.With(...)
.(...)
.Sagas(s => s.StoreInSqlServer(connectionString, "Sagas", "SagaIndex"))
.Start();
By default, the SQL Server saga storage will go and ensure that the two tables specified in the configuration are created, so in this case the tables [dbo].[Sagas]
and [dbo].[SagaIndex]
will be created.
If you want to customize the used schema, you can do that as well – just specify the schema and table name explicitly, e.g. like [rebus].[Sagas]
in order to have the table created in the [rebus]
schema (which will automatically be created if it does not already exist).
With SQL Server, the saga data gets serialized as JSON into a single column, and then the configured correlation properties will be saved "on the side" in the configured index table, allowing an otherwise black-box (to SQL Server, at least) blob of JSON to be looked up by the value of some of its properties.