Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Provides an implementation of Rebus.Outbox abstraction using MS SQL Server as an outbox storage

License

Notifications You must be signed in to change notification settings

rsivanov/Rebus.SqlServer.Outbox

Repository files navigation

Rebus.SqlServer.Outbox

Provides an implementation of Rebus.Outbox abstraction using MS SQL Server as an outbox storage.

Build NuGet NuGet

How to use

Here's a code fragment from the sample application:

services.AddRebus(configure => configure
    .Transport(x =>
    {
        x.UseRabbitMq(rabbitMqConnectionString, rabbitMqOptions.InputQueueName);
    })
    .Outbox(c => c.UseSqlServer(() =>
    {
        var dbConnection = (DbConnection) SqlConnectionFactory.GetOpenConnection(dataAccessOptions.ConnectionString);
        return Task.FromResult(dbConnection);
    }, "dbo.OutboxMessages"), options =>
    {
        options.RunMessagesProcessor = true;
        options.MaxMessagesToRetrieve = 5;
    })
    .Routing(r => r.TypeBased()));

The key point is to have some method of sharing database connections between Outbox and business services. I use Rsi.LocalTransactions for that:

public static class SqlConnectionFactory
{
    public static SqlConnection GetOpenConnection(string connectionString)
    {
        var currentScope = DbConnectionScope.Current;
        if (currentScope != null)
        {
            return (SqlConnection) DbConnectionScope.Current.GetOpenConnection(SqlClientFactory.Instance, connectionString);
        }

        var sqlConnection = (SqlConnection) SqlClientFactory.Instance.CreateConnection();
        sqlConnection.ConnectionString = connectionString;
        sqlConnection.Open();
        return sqlConnection;
    }
}

About

Provides an implementation of Rebus.Outbox abstraction using MS SQL Server as an outbox storage

Resources

License

Stars

Watchers

Forks

Packages

No packages published