1

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.

JoaoVelho
  • 17
  • 2

1 Answers1

0

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

services.AddOptions<EntityFrameworkOutboxOptions>()
    .Configure(options => options.IsolationLevel = IsolationLevel.Serializable);
Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • Sorry, but I don't see how I could change the isolation level from an specific consumer using this setting. Could you give me an example, please? I have other consumers in my app that I would like the isolation level to be RepeatableRead and only a few of them to be Serializable. EDIT: And I'm using Masstransit version 8.0.6 – JoaoVelho Jan 18 '23 at 12:26
  • You can't change it per-consumer, it's a container-wide configuration setting that would apply to all consumers. – Chris Patterson Jan 18 '23 at 16:51