MassTransit Transactional Outbox Isolation Level per Consumer

311 views Asked by At

I have a consumer where I begin a serializable transaction.

public class Consumer : IConsumer<Message>
{
        public async Task Consume(ConsumeContext<Message> context)
        {
            using var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable);
            
            // Do Something

            transaction.Commit();
        }
}

I'm trying to use the new MassTransit Transactional Outbox, but with the outbox configured I can't open this inside transaction because all consumers become wrapped in a transaction and it doesn't allow nested transactions.

One way that I see to solve this is changing the outbox transaction isolation level to serializable so I don't need to open this one inside the consumer, but I don't want to change the isolation level on all my outbox consumers.

Is there a way to configure the outbox transaction isolation level per consumer?

If not, is there another way I could to solve this?

I figured out how to change the isolation level for all the outbox consumers, but didn't find how to change it individually.

1

There are 1 answers

2
Chris Patterson On BEST ANSWER

You can configure the IsolationLevel by adding and configuring the options as shown below:

services.AddOptions<EntityFrameworkOutboxOptions>()
    .Configure(options => options.IsolationLevel = IsolationLevel.Serializable);