[英]MessageLockLostException breaks Service Bus QueueClient
I have service which listens to Service Bus Queue. 我有监听服务总线队列的服务。 Once in a few days I receive
MessageLockLostException
. 几天后,我会收到
MessageLockLostException
。 Exception itself is clear for me and that's not an issue. 异常本身对我来说很明显,这不是问题。 However QueueClient seems broken after exception received and stops processing any further messages.
但是,在收到异常后,QueueClient似乎已损坏,并停止处理任何其他消息。 I understand that i can add
try / catch
to ProcessMessagesAsync
. 我知道我可以将
try / catch
添加到ProcessMessagesAsync
。 However I thought that ExceptionReceivedHandler
should handle such cases and QueueClient should try to process same message again(or send it to DLQ if it fails to process it multiple time). 但是我认为
ExceptionReceivedHandler
应该处理这种情况,而QueueClient应该尝试再次处理同一条消息(如果多次处理失败,则将其发送到DLQ)。
public class QueueService
{
private readonly QueueClient _queueClient;
public QueueServiceServiceBus(string connectionString, ILogger<QueueServiceServiceBus> logger)
{
_logger = logger;
var serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
_queueClient = new QueueClient(serviceBusConnectionStringBuilder);
RegisterMessageHandler();
}
private Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
{
_logger.LogError("Message handler encountered an exception {Exception}",
exceptionReceivedEventArgs.Exception);
return Task.CompletedTask;
}
private async Task ProcessMessagesAsync(Message message, CancellationToken token)
{
//Handle message
await _queueClient.CompleteAsync(message.SystemProperties.LockToken);
}
private void RegisterMessageHandler()
{
var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
{
AutoComplete = false
};
_queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
}
}
ExceptionReceivedHandler
handles the exceptions which occurs during the retrieval and processing of the messages. ExceptionReceivedHandler
处理在消息的检索和处理期间发生的异常。
The QueueClient
will not break for any reason unless it gets throttled with over load. 除非因过载而受到限制,否则
QueueClient
不会因任何原因而中断。
I tried the sample what you provided. 我尝试了您提供的样本。 It works fine for me, the
ExceptionReceivedHandler
handles the MessageLockLostException
without breaking. 它对我来说很好用,
ExceptionReceivedHandler
处理MessageLockLostException
而不会中断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.