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