【发布时间】:2013-04-04 03:25:15
【问题描述】:
我正在使用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 中。
有人知道怎么做吗?
【问题讨论】:
-
如果消费者实例是从会话创建的,那么会话可能已经创建,因此在委托运行期间 (Transaction.Current) 周围存在环境事务。