简体   繁体   English

每个消费者的 MassTransit 交易发件箱隔离级别

[英]MassTransit Transactional Outbox Isolation Level per Consumer

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.我正在尝试使用新的 MassTransit Transactional Outbox,但配置了发件箱后我无法打开此内部事务,因为所有消费者都包含在一个事务中并且它不允许嵌套事务。

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.我想出了如何更改所有发件箱使用者的隔离级别,但没有找到如何单独更改它。

You can configure the IsolationLevel by adding and configuring the options as shown below:您可以通过添加和配置选项来配置IsolationLevel ,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM