【问题标题】:Receiving message in a transaction在事务中接收消息
【发布时间】:2015-12-03 03:38:26
【问题描述】:

我正在编写一个基本的 MSMQ 生产者和消费者,但在尝试接收作为事务的一部分的消息时遇到了问题。

队列位于 Windows Server 2003 机器上,并且肯定设置为事务性。我的生产者能够毫无问题地将消息作为事务的一部分放入队列。只要我不在事务中这样做,我也可以毫无问题地从队列中读取消息。我做错了什么?

这是我尝试使用队列的代码块:

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");
    }
}

因此,如果我删除 using (MessageQueueTransaction ...) 封装,一切正常,当然我不能 commitabort 交易取决于 ParseMessage(...) 的布尔结果

不过,当我添加事务位时,只要我点击msgQ.Receive(...) 行,我就会得到一个MessageQueueException。异常消息和基数为空,MessageQueueErrorCode0xc00e008b,根据this MSDN page 转换为:

MQ_ERROR_OPERATION_NOT_SUPPORTED_BY_REMOTE_COMPUTER (0xC00E008B)

当尝试接收或查看消息时返回 来自远程队列的查找标识符,位于正在运行的计算机上 MSMQ 1.0 或 MSMQ 2.0。

现在,据我所知,我并没有尝试根据查找标识符接收或查看,MSMQ 在 Windows Server 2003 上运行,这意味着它应该是 MSMQ 3.0。

我在这里做错了什么?

【问题讨论】:

    标签: c# msmq msmq-transaction


    【解决方案1】:

    您正在执行远程事务接收。这是在 MSMQ 4.0 中引入的。将服务器升级到支持的操作系统。

    How do I get transactional remote receives with MSMQ?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多