[英]Receiving message in a transaction
I am writing a basic MSMQ producer and consumer and I'm getting tripped up when trying to receive a message as part of a transaction. 我正在写一个基本的MSMQ生产者和消费者,当尝试接收消息作为事务的一部分时,我陷入了困境。
The queue is on a Windows Server 2003 machine and it is definitely set to transactional. 该队列位于Windows Server 2003计算机上,并且绝对设置为事务性队列。 My producer is able to put messages onto the queue as part of a transaction with no problems.
我的生产者能够将消息作为事务的一部分放入队列中而没有任何问题。 I can read the messages off the queue without problems as well, as long as I don't do it in a transaction.
只要不在事务中进行处理,我也可以毫无问题地从队列中读取消息。 What am I doing wrong?
我究竟做错了什么?
This is the block of code with which I'm trying to consume the queue: 这是我尝试使用队列的代码块:
using (MessageQueue msgQ = new MessageQueue(myQueueName))
{
try
{
using (MessageQueueTransaction msgTx = new MessageQueueTransaction())
{
msgTx.Begin();
msg = msgQ.Receive(new TimeSpan(0, 0, 0, 0, 1000), msgTx);
Console.WriteLine("Message " + msg.LookupId.ToString() + " received");
msg.Formatter = new XmlMessageFormatter(new string[] { "System.String,mscorlib" });
if (ParseMessage(msg.Body.ToString()))
{
msgTx.Commit();
Console.WriteLine("Message " + msg.LookupId.ToString() + " delivered");
}
else
{
msgTx.Abort();
Console.WriteLine("Message " + msg.LookupId.ToString() + " not delivered");
}
}
}
catch (MessageQueueException exc)
{
if (exc.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
Console.WriteLine("No more messages available");
else
Console.WriteLine("Unknown error encountered while receiving");
}
}
So if I remove the using (MessageQueueTransaction ...)
encapsulation, everything works fine, except of course that I can't commit
or abort
the transaction depending on the boolean outcome of ParseMessage(...)
因此,如果我删除了
using (MessageQueueTransaction ...)
封装,则一切正常,但根据ParseMessage(...)
的布尔结果,我当然不能commit
或abort
事务ParseMessage(...)
When I add the transactional bits though, I get a MessageQueueException
as soon as I hit the msgQ.Receive(...)
line. 但是,当我添加事务性位时,只要碰到
msgQ.Receive(...)
行,就会收到MessageQueueException
。 The exception message and base is null and the MessageQueueErrorCode
is 0xc00e008b
which, according to this MSDN page translates to: 异常消息和基为null,
MessageQueueErrorCode
为0xc00e008b
,根据此MSDN页面,它转换为:
MQ_ERROR_OPERATION_NOT_SUPPORTED_BY_REMOTE_COMPUTER (0xC00E008B)
MQ_ERROR_OPERATION_NOT_SUPPORTED_BY_REMOTE_COMPUTER(0xC00E008B)
Returned when an attempt is made to receive or peek at a message using a lookup identifier from a remote queue residing on a computer running MSMQ 1.0 or MSMQ 2.0.
当尝试使用驻留在运行MSMQ 1.0或MSMQ 2.0的计算机上的远程队列中的查找标识符来接收或查看消息时返回。
Now, to the best of my knowledge, I'm not trying to receive or peek based on a lookup identifier plus, the MSMQ is running on Windows Server 2003 which means it should be MSMQ 3.0 anyway. 现在,据我所知,我并不是在尝试基于查找标识符进行接收或窥视,而且MSMQ正在Windows Server 2003上运行,这意味着它应该仍然是MSMQ 3.0。
What am I getting wrong here? 我这是怎么了?
You are performing a Remote Transactional Receive. 您正在执行远程事务接收。 This was introduced in MSMQ 4.0.
这是在MSMQ 4.0中引入的。 Upgrade the server to a supported operating system.
将服务器升级到支持的操作系统。
How do I get transactional remote receives with MSMQ?
如何使用MSMQ获得事务性远程接收?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.