gpt4 book ai didi

servicebus - Windows Server 的服务总线 2.1 - EndReceive 方法上的 TimeOutException

转载 作者:行者123 更新时间:2023-12-04 12:54:23 25 4
gpt4 key购买 nike

我正在使用 Service Bus 2.1 For Windows Server,并且我有一种异步接收消息的方法。

我的方法的主体是:

var waitTimeout = TimeSpan.FromSeconds(10);

// Declare an action acting as a callback whenever a message arrives on a queue.
AsyncCallback completeReceive = null;

// Declare an action acting as a callback whenever a non-transient exception occurs while receiving or processing messages.
Action<Exception> recoverReceive = null;

// Declare an action responsible for the core operations in the message receive loop.
Action receiveMessage = () =>
{
// Use a retry policy to execute the Receive action in an asynchronous and reliable fashion.
retryPolicy.ExecuteAction(
(cb) => messageReceiver.BeginReceive(waitTimeout, cb, null),
(ar) =>
{
// Make sure we are not told to stop receiving while we were waiting for a new message.
if (!cts.IsCancellationRequested)
{
// Complete the asynchronous operation. This may throw an exception that will be handled internally by retry policy.
BrokeredMessage msg = messageReceiver.EndReceive(ar);

// Check if we actually received any messages.
if (msg != null)
{
// Make sure we are not told to stop receiving while we were waiting for a new message.
if (!cts.IsCancellationRequested)
{
try
{
// Process the received message.
processMessage(msg);

// With PeekLock mode, we should mark the processed message as completed.
if (messageReceiver.Mode == ReceiveMode.PeekLock)
{
// Mark brokered message as completed at which point it's removed from the queue.
msg.SafeComplete();
}
}
catch
{
// With PeekLock mode, we should mark the failed message as abandoned.
if (messageReceiver.Mode == ReceiveMode.PeekLock)
{
// Abandons a brokered message. This will cause Service Bus to unlock the message and make it available
// to be received again, either by the same consumer or by another completing consumer.
msg.SafeAbandon();
}

// Re-throw the exception so that we can report it in the fault handler.
throw;
}
finally
{
// Ensure that any resources allocated by a BrokeredMessage instance are released.
msg.Dispose();
}
}
else
{
// If we were told to stop processing, the current message needs to be unlocked and return back to the queue.
if (messageReceiver.Mode == ReceiveMode.PeekLock)
{
msg.SafeAbandon();
}
}
}
}

// Invoke a custom callback method to indicate that we have completed an iteration in the message receive loop.
completeReceive(ar);
},
() =>
{

},
(ex) =>
{
// Invoke a custom action to indicate that we have encountered an exception and
// need further decision as to whether to continue receiving messages.
recoverReceive(ex);
});
};

// Initialize a custom action acting as a callback whenever a message arrives on a queue.
completeReceive = (ar) =>
{
if (!cts.IsCancellationRequested)
{
// Continue receiving and processing new messages until we are told to stop.
receiveMessage();
}
};

// Initialize a custom action acting as a callback whenever a non-transient exception occurs while receiving or processing messages.
recoverReceive = (ex) =>
{
if (!cts.IsCancellationRequested)
{
// Continue receiving and processing new messages until we are told to stop regardless of any exceptions.
receiveMessage();
}
};

// Start receiving messages asynchronously.
receiveMessage();

由于我已将 dll Microsoft.ServiceBus 更新到 2.1 版(在我使用 1.8 版和 2.0 版之前),我每秒都会有两个异常(exception):

Microsoft.ServiceBus.dll 中发生了“System.ServiceModel.FaultException`1”类型的第一次机会异常
Microsoft.ServiceBus.dll 中发生了“System.TimeoutException”类型的第一次机会异常

引发异常的方法是:
'EndReceive' 和 Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)

我在互联网上看到了一些帖子,但没有任何答案。
有人已经遇到这个问题了吗?

最佳答案

我在 Servicebus 库的 2.05 版中遇到了同样的问题。我更新到 3.0,它解决了这个问题。

关于servicebus - Windows Server 的服务总线 2.1 - EndReceive 方法上的 TimeOutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271035/

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