Async Consumer和TransactionScope的使用

Joh*_*ons 7 c# ibm-mq

我正在使用IBM.XMS lib与WebSphereMQ交谈.

使用同步方法接收消息时,例如:

using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
       message = consumer.Receive(1000);

       if (message != null)
       {
            //Do work here
            scope.Complete();
       }
}
Run Code Online (Sandbox Code Playgroud)

但是如果我想使用异步方法:

consumer.MessageListener = delegate(IMessage msg)
{
    //Do work here
    //But where do I put TransactionScope?
};
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何MessageListener在一个回调中包装回调TransactionScope.

有谁知道如何做到这一点?

Sha*_*shi 1

消息监听器又名异步消费者不能在 a 中使用,TransactionScope因为消息监听器运行在与创建 . 的线程不同的线程上TransactionScope。您只能在TransactionScope.

链接显示“异步使用者不支持 XA 事务”。