簡體   English   中英

接收交易中的消息

[英]Receiving message in a transaction

我正在寫一個基本的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 ...)封裝,則一切正常,但根據ParseMessage(...)的布爾結果,我當然不能commitabort事務ParseMessage(...)

但是,當我添加事務性位時,只要碰到msgQ.Receive(...)行,就會收到MessageQueueException 異常消息和基為null, MessageQueueErrorCode0xc00e008b ,根據此MSDN頁面,它轉換為:

MQ_ERROR_OPERATION_NOT_SUPPORTED_BY_REMOTE_COMPUTER(0xC00E008B)

當嘗試使用駐留在運行MSMQ 1.0或MSMQ 2.0的計算機上的遠程隊列中的查找標識符來接收或查看消息時返回。

現在,據我所知,我並不是在嘗試基於查找標識符進行接收或窺視,而且MSMQ正在Windows Server 2003上運行,這意味着它應該仍然是MSMQ 3.0。

我這是怎么了?

您正在執行遠程事務接收。 這是在MSMQ 4.0中引入的。 將服務器升級到支持的操作系統。

如何使用MSMQ獲得事務性遠程接收?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM