Skip to content

PostgreSQL Integration


Wolverine can happily use the PostgreSQL durability options with any mix of Entity Framework Core and/or Marten as a higher level persistence framework

Wolverine supports a PostgreSQL backed message persistence strategy and even a PostgreSQL backed messaging transport option. To get started, add the WolverineFx.Postgresql dependency to your application:

dotnet add package WolverineFx.Postgresql

Message Persistence

To enable PostgreSQL to serve as Wolverine's transactional inbox and outbox, you just need to use the WolverineOptions.PersistMessagesWithPostgresql() extension method as shown below in a sample:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("postgres");

builder.Host.UseWolverine(opts =>
    // Setting up Postgresql-backed message storage
    // This requires a reference to Wolverine.Postgresql

    // Other Wolverine configuration

// This is rebuilding the persistent storage database schema on startup
// and also clearing any persisted envelope state

var app = builder.Build();

// Other ASP.Net Core configuration...

// Using Oakton opens up command line utilities for managing
// the message storage
return await app.RunOaktonCommands(args);

snippet source | anchor

PostgreSQL Messaging Transport 2.5


All PostgreSQL queues are built into a wolverine_queues schema at this point.

The WolverineFx.PostgreSQL Nuget also contains a simple messaging transport that was mostly meant to be usable for teams who want asynchronous queueing without introducing more specialized infrastructure. To enable this transport in your code, use this option which also activates PostgreSQL backed message persistence:

using var host = await Host.CreateDefaultBuilder()
    .UseWolverine((context, opts) =>
        var connectionString = context.Configuration.GetConnectionString("postgres");
        opts.UsePostgresqlPersistenceAndTransport(connectionString, "myapp")

            // Tell Wolverine to build out all necessary queue or scheduled message
            // tables on demand as needed

            // Optional that may be helpful in testing, but probably bad
            // in production!

        // Use this extension method to create subscriber rules

        // Use this to set up queue listeners

            .CircuitBreaker(cb =>
                // fine tune the circuit breaker
                // policies here

            // Optionally specify how many messages to
            // fetch into the listener at any one time

snippet source | anchor

The PostgreSQL transport is strictly queue-based at this point. The queues are configured as durable by default, meaning that they are utilizing the transactional inbox and outbox. The PostgreSQL queues can also be buffered:


snippet source | anchor

Using this option just means that the PostgreSQL queues can be used for both sending or receiving with no integration with the transactional inbox or outbox. This is a little more performant, but less safe as messages could be lost if held in memory when the application shuts down unexpectedly.


If utilizing the PostgreSQL transport with Marten multi-tenancy through separate databases per tenant, the PostgreSQL queues will be built an monitored for each tenant database as well as any master database.

Integration with Marten

The PostgreSQL message persistence and transport is automatically included with the AddMarten().IntegrateWithWolverine() configuration syntax.

Released under the MIT License.