Marten Integration
INFO
There is also some HTTP specific integration for Marten with Wolverine. See Integration with Marten for more information.
Marten and Wolverine are sibling projects under the JasperFx organization, and as such, have quite a bit of synergy when used together. At this point, adding the WolverineFx.Marten
Nuget dependency to your application adds the capability to combine Marten and Wolverine to:
- Simplify persistent handler coding with transactional middleware
- Use Marten and Postgresql as a persistent inbox or outbox with Wolverine messaging
- Support persistent sagas within Wolverine applications
- Effectively use Wolverine and Marten together for a Decider function workflow with event sourcing
- Selectively publish events captured by Marten through Wolverine messaging
- Process events captured by Marten through Wolverine message handlers through either subscriptions or the older event forwarding.
Getting Started
To use the Wolverine integration with Marten, just install the Wolverine.Persistence.Marten Nuget into your application. Assuming that you've configured Marten in your application (and Wolverine itself!), you next need to add the Wolverine integration to Marten as shown in this sample application bootstrapping:
var builder = WebApplication.CreateBuilder(args);
builder.Host.ApplyOaktonExtensions();
builder.Services.AddMarten(opts =>
{
opts.Connection(Servers.PostgresConnectionString);
opts.DatabaseSchemaName = "chaos2";
})
.IntegrateWithWolverine();
builder.Host.UseWolverine(opts =>
{
opts.Policies.OnAnyException().RetryWithCooldown(50.Milliseconds(), 100.Milliseconds(), 250.Milliseconds());
opts.Services.AddScoped<IMessageRecordRepository, MartenMessageRecordRepository>();
opts.Policies.DisableConventionalLocalRouting();
opts.UseRabbitMq().AutoProvision();
opts.Policies.UseDurableInboxOnAllListeners();
opts.Policies.UseDurableOutboxOnAllSendingEndpoints();
opts.ListenToRabbitQueue("chaos2");
opts.PublishAllMessages().ToRabbitQueue("chaos2");
opts.Policies.AutoApplyTransactions();
});
var builder = WebApplication.CreateBuilder(args);
builder.Host.ApplyOaktonExtensions();
builder.Services.AddMarten(opts =>
{
var connectionString = builder
.Configuration
.GetConnectionString("postgres");
opts.Connection(connectionString);
opts.DatabaseSchemaName = "orders";
})
// Optionally add Marten/Postgresql integration
// with Wolverine's outbox
.IntegrateWithWolverine();
// You can also place the Wolverine database objects
// into a different database schema, in this case
// named "wolverine_messages"
//.IntegrateWithWolverine("wolverine_messages");
builder.Host.UseWolverine(opts =>
{
// I've added persistent inbox
// behavior to the "important"
// local queue
opts.LocalQueue("important")
.UseDurableInbox();
});
For more information, see durable messaging and the sample Marten + Wolverine project.
Using the IntegrateWithWolverine()
extension method behind your call to AddMarten()
will:
- Register the necessary inbox and outbox database tables with Marten's database schema management
- Adds Wolverine's "DurabilityAgent" to your .NET application for the inbox and outbox
- Makes Marten the active saga storage for Wolverine
- Adds transactional middleware using Marten to your Wolverine application
Marten as Outbox
See the Marten as Outbox page.
Transactional Middleware
See the Transactional Middleware page.
Marten as Inbox
See the Marten as Inbox page.
Saga Storage
See the Marten as Saga Storage page.