gpt4 book ai didi

c# - 如果我的函数在处理时失败,System.MessageQueue (MSMQ) 消息是否会丢失?

转载 作者:行者123 更新时间:2023-11-30 13:29:23 26 4
gpt4 key购买 nike

我使用以下代码发送消息:

var transaction = new MessageQueueTransaction())
transaction.Begin( );

var message = new Message
{
Body = myContent,
Recoverable = true
};

m_oMessageQueue.Send( message , myTransaction );

transaction.Commit( );

并使用 BeginRecieveReceiveCompleted 事件处理程序接收它。

如果我的事件处理程序在调用 EndRecieve 之前失败,消息是否应该保留在队列中并可供后续调用接收?我看到的行为是消息永远消失了。 (或者可能有一个超时时间,在该时间点之后它会再次可用?)

更新接收消息的代码如下所示。

var messageQueue = new MessageQueue( myPath );
messageQueue.ReceiveCompleted += messageQueue_ReceiveCompleted_ThrowException;
messageQueue.BeginReceive();

出于测试目的,我在 messageQueue_ReceiveCompleted_ThrowException 事件处理程序中抛出异常。

然后我用一个有效的事件处理程序重复上面的代码,但我没有被调用。

最佳答案

看起来问题在于您将 BeginReceive 与事务队列一起使用。 From MSDN :

Note Do not use the asynchronous call BeginReceive with transactions. If you want to perform a transactional asynchronous operation, call BeginPeek, and put the transaction and the (synchronous) Receive method within the event handler you create for the peek operation. Your event handler might contain functionality as shown in the following C# code.

对于这样的失败,我认为消息通常会进入死信队列或产生否定确认,具体取决于您如何配置 MessageQueue(这可以解释为什么您看不到它们) .你可以read more about those options here .

关于c# - 如果我的函数在处理时失败,System.MessageQueue (MSMQ) 消息是否会丢失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1405855/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com