zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
467 stars 78 forks source link

[Host.Outbox] Support for nested transactions #218

Closed szczupi closed 5 months ago

szczupi commented 6 months ago

In our setup, we use Outbox for Azure Service Bus and Sql transactions for in-memory bus.

`mbb
    .AddChildBus("Command", x => x.WithProviderMemory()
        .UseSqlTransaction())
    .AddChildBus("AzureSB", x =>
    {
        x.WithProviderServiceBus(
            cfg =>
            {
            });
        x.UseOutbox();
    })
    .AddOutboxUsingDbContext<TContext>(x => { });`

In one of the use cases, we'd like to send a message from one request handler that will be handled by another 'In memory' request handler. Unfortunately, the outbox is trying to span a new SQL Transaction, although one already exists, which ends up with an exception. Is it possible to discover and use existing transactions when invoking the "nested" request handler?

zarusz commented 5 months ago

Nested transactions are now supported since this release: https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext/2.3.0-rc5 https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql/2.3.0-rc5

The 2.3.0 version will be released soon.