gpt4 book ai didi

c# - 异步消费者和 TransactionScope 的使用

转载 作者:太空狗 更新时间:2023-10-29 20:36:48 26 4
gpt4 key购买 nike

我正在使用 IBM.XMS lib与 WebSphereMQ 对话。

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

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

if (message != null)
{
//Do work here
scope.Complete();
}
}

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

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

我不知道如何将 MessageListener 回调包装在 TransactionScope 中。

有人知道怎么做吗?

最佳答案

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

link说“异步消费者不支持 XA 事务。”

关于c# - 异步消费者和 TransactionScope 的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15801997/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com