简体   繁体   English

MessageLockLostException中断服务总线QueueClient

[英]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.

相关问题 Windows Azure服务总线队列 - MessageSender或QueueClient? - Windows Azure Service Bus Queues - MessageSender or QueueClient? 完成锁定消息时的 Azure 服务总线 MessageLockLostException - Azure Service Bus MessageLockLostException when Completing Locked Message 取消长期运行接收的Azure Service Bus QueueClient? - Cancel an Azure Service Bus QueueClient long running Receive? 当锁定持续时间未过去时,Azure 服务总线为非分区队列抛出 MessageLockLostException - Azure Service Bus throwing MessageLockLostException for non-partitioned queue when lock duration has not passed Azure服务总线队列-当消息在队列中时,QueueClient.Receive()返回空的BrokeredMessage - Azure Service Bus Queue - QueueClient.Receive() returning null BrokeredMessage when messages are in the queue 如何测试QueueClient是否可以成功连接到Azure服务总线队列? - How can I test if QueueClient can successfully connect to an Azure Service Bus Queue? 调用QueueClient.CreateFromConnectionString时使用C#的Azure服务总线队列:BadImageFormatException - Azure Service bus Queue using C# : BadImageFormatException when calling QueueClient.CreateFromConnectionString Azure服务总线AutoDeleteOnIdle - Azure Service Bus AutoDeleteOnIdle 在内存服务总线(NServiceBus) - In memory Service Bus (NServiceBus) 服务总线IAsyncResult - Service Bus IAsyncResult
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM