masstransit

MassTransit SQL Server Transport and EntityFramework Outbox


Note: This is with the latest 8.3.0 version

I am trying to use the bus outbox with the new SQL Server Transport and seem to be having an issue where the messages are published immediately to the SQL Transport and not to my EF outbox setup. I'm saving my aggregate and the outbox all in a single transaction that includes the outbox. The idea being that this is a single atomic transaction, and that the outbox infrastructure will pick up the outbox messages afterwards and publish it to the SQL Transport but this isn't what is happening.

I've used this setup before with a different transport (Azure Service Bus) and know that it works very well. Does the outbox functionality not work with the SQL Transport?

Here is my code setup, I am using the ISecondBus pattern because I do have a default bus that is Azure Service Bus but I have commented all of that out for now and hyper focusing on just the SQL Transport and it is still not working.

        //Add SQL Transport Bus
        services.AddMassTransit<ISqlTransportBus>(x =>
        {
            x.AddEntityFrameworkOutbox<AdminDbContext>(o =>
            {
                o.DuplicateDetectionWindow = TimeSpan.FromSeconds(30);
                o.QueryDelay = TimeSpan.FromSeconds(2);
                o.UseSqlServer();

                o.UseBusOutbox(config =>
                {
                    //config.DisableDeliveryService();
                });
            });
            x.AddSqlMessageScheduler();

            //Add Consumers
            x.AddConsumer<MyConsumer1>();

            //setup sql db transport for domain events
            x.UsingSqlServer((context, cfg) =>
            {
                cfg.UseSqlMessageScheduler();
                cfg.AutoStart = true;
                cfg.UseMessageRetry(r => r.Intervals(100, 500, 1000, 5000, 10000));
                cfg.MessageTopology.SetEntityNameFormatter(new PrefixEntityNameFormatter(
                    cfg.MessageTopology.EntityNameFormatter,
                    string.IsNullOrWhiteSpace(prefix) ? string.Empty : $"{prefix}"));

                cfg.Send<MyDomainEvent1>(x => { });
                cfg.ConfigureEndpoints(context, a =>
                {
                    a.Include<MyConsumer1>();
                });

                
            });

        });

Solution

  • The transactional outbox only works with the default IBus, it does not work with MultiBus instances.

    The transactional outbox works perfectly fine with the SQL transport.