简体   繁体   English

消息工作成功完成后,Azure Service Bus“提供的锁无效”

[英]Azure Service Bus “The lock supplied is invalid” after message work successfully completed

I've an Azure Web Job with the following initialization code 我有一个Azure Web作业,其中包含以下初始化代码

class Program
{
    static void Main(string[] args)
    {
        IHostBuilder builder = new HostBuilder()
        .ConfigureWebJobs(b =>
        {
            b.AddServiceBus((opt) =>
            {
                opt.ConnectionString = "Connection string";
                opt.MessageHandlerOptions = new MessageHandlerOptions((ex) =>
                {
                    return Task.Run(() =>
                    {
                        // logging the error message
                    });
                })
                {
                    MaxAutoRenewDuration = new TimeSpan(0, 0, 5, 0),
                    MaxConcurrentCalls = 1
                };
            });
        })
        .UseConsoleLifetime();

        IHost host = builder.Build();
        using (host)
        {
            host.Run();
        }
    }
}

The Service Bus queue is configured to have a Lock Duration of 5 minutes, that is the maximum time that Azure allows. Service Bus队列配置为具有5分钟的锁定持续时间,即Azure允许的最长时间。 The message processing can take more than 30 minutes and the lock renew mechanism works correctly. 消息处理可能需要30多分钟,并且锁更新机制可以正常工作。 When the process ends correctly, an exception is thrown The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance 当进程正确结束时,抛出异常The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance and the message goes back to the queue again. The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance ,并且消息再次返回到队列。

When you call messsage.Complete() (or CompleteAsync() ) then you should instantiate an MessageHandlerOptions object, set AutoComplete to false , and pass it into your message handler registration. 当您调用messsage.Complete() (或CompleteAsync() )时,您应该实例化MessageHandlerOptions对象,将AutoComplete设置为false ,并将其传递给您的消息处理程序注册。

new MessageHandlerOptions(OnException)
{
    AutoComplete = false,
    MaxConcurrentCalls = MaxConcurrentCalls, // 1
    MaxAutoRenewDuration = MaxAutoRenewDuration // 2 hrs
}

For more details, you could refer to this article . 有关更多详细信息,请参阅此文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 作为Web作业的Azure Service Bus引发错误提供的锁无效 - Azure Service Bus as Web Job throw error The lock supplied is invalid Azure 服务总线 - MaxConcurrentCalls=1 - 提供的锁无效。 要么锁过期 - Azure Service Bus - MaxConcurrentCalls=1 - The lock supplied is invalid. Either the lock expired 尽管WebJobs SDK处理程序成功完成,但Service Bus消息已被放弃 - Service Bus message abandoned despite WebJobs SDK handler completed successfully Azure服务总线消息锁是否未续订? - Azure Service Bus message lock not being renewed? azure function V2 中的延迟消息:提供的锁无效 - Defer message in azure function V2: The lock supplied is invalid Azure 服务总线队列消息锁定在 UTC 午夜到期 - Azure Service Bus queue message lock expires at midnight UTC 如何处理不带锁定令牌的Azure服务总线代理消息? - How to process azure service bus brokered message without lock token? Azure Service Bus队列最大批量更新消息锁定以进行批处理 - Azure Service Bus Queue Maximum Renewal of Message Lock for Batch Processing Azure服务总线队列消息在Message.Abandon之后崩溃 - Azure service bus queue Message deadlettered after Message.Abandon 在经过一段时间后重试 azure 服务总线上的消息? - Retrying a message on azure service bus after an elapsed time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM