[英]Azure Service Bus Topic Subscriber lock expired exception
I have an web job that consumes message from Azure Service Bus Topic by registering a OnMessage
callback . 我有一个Web作业,通过注册
OnMessage
回调来使用Azure服务总线主题中的消息。 The message lock duration was set to 30 seconds and the lock renew timeout to 60 seconds . 消息锁定持续时间设置为30秒 , 锁定更新超时设置为60秒 。 As such jobs taking more than 30 seconds to process service bus message were getting lock expired exception.
由于此类作业需要30秒钟以上的时间来处理服务总线消息,因此发生了锁过期异常。
Now,I have set the message lock duration to more than lock renew time out. 现在,我已将消息锁定持续时间设置为大于锁定更新超时时间。 But somehow it still throws same exception.
但是不知何故,它仍然抛出相同的异常。 I also restarted my webjob, but still no luck.
我也重新开始了我的网络工作,但是仍然没有运气。
I tried running same webjob consuming messages from different topic with later settings and it works fine. 我尝试使用更高的设置运行来自不同主题的 相同webjob消耗消息,但效果很好。 Is this behaviour expected, and after how much time does this setting change normally reflect.
这是预期的行为吗?此设置更改会在多少时间后正常反映出来。
Any help will be great 任何帮助都会很棒
I have set the message lock duration to more than lock renew time out.
我已将消息锁定持续时间设置为大于锁定更新超时时间。 But somehow it still throws same exception.
但是不知何故,它仍然抛出相同的异常。
The max value of lock duration is 5 min. 锁定持续时间的最大值为5分钟。 If you need less than 5 min to process the job, you could increase the lock duration of your message to meet your requirement.
如果您需要不到5分钟的时间来处理作业,则可以增加消息的锁定时间,以满足您的要求。
If you need more than 5 min to process your job , you need to set the AutoRenewTimeout property of OnMessageOptions. 如果需要5分钟以上的时间来处理作业 ,则需要设置OnMessageOptions的AutoRenewTimeout属性。 It will renew the lock if the lock expired before it reached the AutoRenewTimeout.
如果锁在到达AutoRenewTimeout之前已过期,它将更新锁。 For example, if you set lock duration to 1 min and set AutoRenewTimeout to 5 min.
例如,如果将锁定持续时间设置为1分钟,并将AutoRenewTimeout设置为5分钟。 The message will keep in locked for up to 5 min if you don't release the lock.
如果您不释放锁,该消息将保持锁定状态最多5分钟。
Here are the sample code I used to test the lock duration and AutoRenewTimeout on my side. 这是我用来测试锁定持续时间和AutoRenewTimeout的示例代码。 If the job spent more time than lock duration and AutoRenewTimeout, it will throw a exception when we complete the message(it means timeout happened).
如果作业花费的时间超过锁定持续时间和AutoRenewTimeout,它将在我们完成消息后抛出异常(这表示发生了超时)。 I also modified the lock duration on portal and the configuration will be applied immediately when I receive a message.
我还修改了门户网站上的锁定时间,并且在收到消息时将立即应用该配置。
SubscriptionClient Client = SubscriptionClient.CreateFromConnectionString(connectionString, "topic name", "subscription name");
// Configure the callback options.
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromSeconds(60);
Client.OnMessage((message) =>
{
try
{
//process the message here, I used following code to simulation a long time spent job
for (int i = 0; i < 30; i++)
{
Thread.Sleep(3000);
}
// Remove message from subscription.
message.Complete();
}
catch (Exception ex)
{
// Indicates a problem, unlock message in subscription.
message.Abandon();
}
}, options);
For your issue, please check how much time will be spent on your job and choose a right way to set lock duration and AutoRenewTimeout. 对于您的问题,请检查您的工作将花费多少时间,并选择一种正确的方法来设置锁定持续时间和AutoRenewTimeout。
The settings should be reflected almost immediately. 设置应几乎立即反映出来。 Also lock renewal should probably be more than the lock duration or disabled.
同样,锁更新可能应该超过锁持续时间或被禁用。
Lock renewal feature is ASB client feature and it doesn't override lock duration set on entities. 锁定更新功能是ASB客户端功能,它不会覆盖在实体上设置的锁定持续时间。 If you can reproduce this issue and share the repro, raise a support issue with Microsoft.
如果您可以重现此问题并共享该repro,请向Microsoft提出支持问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.