远程 MSMQ、事务和 ReceiveById 失败 - “在指定的队列中找不到请求的消息”
在远程 MSMQ 中使用事务时,出现错误“在指定的队列中找不到请求的消息”。如果删除事务或将队列移动到同一台机器,则一切正常。队列位于 Windows 2008 计算机上,客户端(代码如下所示)在 Windows 7 计算机上运行。
//Throws above error
using (MessageQueueTransaction mqTxn = new MessageQueueTransaction())
{
mqTxn.Begin();
Message message = messageQueue.ReceiveById(peekedMessage.Id, mqTxn);
mqTxn.Abort();
}
//Throws above error
using (TransactionScope txnScope = new TransactionScope())
{
Message message = messageQueue.ReceiveById(peekedMessage.Id, MessageQueueTransactionType.Automatic);
}
//Works fine
Message message = messageQueue.ReceiveById(peekedMessage.Id);
PS peekedMessage 是在这些调用之前查看的消息。我已验证 peekedMessage.Id 与第一个队列项匹配。队列是事务性的。
I am getting an error "Message requested was not found in the queue specified" when using transactions in remote MSMQ. If transaction is removed or if the queue is moved to same machine, everything works just fine. The queue is on Windows 2008 machine and the client (code shown below) is run on Windows 7 machine.
//Throws above error
using (MessageQueueTransaction mqTxn = new MessageQueueTransaction())
{
mqTxn.Begin();
Message message = messageQueue.ReceiveById(peekedMessage.Id, mqTxn);
mqTxn.Abort();
}
//Throws above error
using (TransactionScope txnScope = new TransactionScope())
{
Message message = messageQueue.ReceiveById(peekedMessage.Id, MessageQueueTransactionType.Automatic);
}
//Works fine
Message message = messageQueue.ReceiveById(peekedMessage.Id);
P.S. peekedMessage is messages peeked just before these calls. I have verified that the peekedMessage.Id matches with the first queue item. The queue is transactional.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MessageQueueTransaction 只能用于内部事务,因此在远程队列情况下不起作用。
第二种方式(使用 TransactionScope)可以像使用 DTC 一样工作。 DTC 应在两端运行并正确配置。默认情况下,DTC 在 Windows 2008 和 Windows 7 中都是关闭的。此外,如果防火墙打开,DTC 将被放入例外列表中。一旦完成,它就像一个魅力。
MessageQueueTransaction can only be used for internal transactions so it won't work in the remote queue case.
The second way (using TransactionScope) would work as it uses DTC. DTC should be running and properly configured on both ends. By default, DTC is turned off both in Windows 2008 and Windows 7. In addition if firewall is on, DTC is to be put in the exception list. As soon as that is done, it works like a charm.