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.

1 Answer 1

1

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

services.AddOptions<EntityFrameworkOutboxOptions>()
    .Configure(options => options.IsolationLevel = IsolationLevel.Serializable);
Sign up to request clarification or add additional context in comments.

2 Comments

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
You can't change it per-consumer, it's a container-wide configuration setting that would apply to all consumers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.