为什么BrokeredMessage.RenewLock()只续签了几秒钟的锁? [英] Why does BrokeredMessage.RenewLock() only renew the lock for a few seconds?

查看:376
本文介绍了为什么BrokeredMessage.RenewLock()只续签了几秒钟的锁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到它使用一个定时器来定期检查和更新上BrokeredMessage实例锁的情况下处理此消息的过程中BrokeredMessageContext类的时间比预期运行。它通过调用BrokeredMessage实例RenewLock()方法更新锁。

I've got a BrokeredMessageContext class which uses a Timer to periodically check and renew the lock on a BrokeredMessage instance in case the process that handles this message runs for longer than expected. It renews the lock by calling the RenewLock() method on the BrokeredMessage instance.

我预计这个调用给我相同的超时作为原始锁了一把新锁( MSDN指出,你可以续订锁相同持续时间作为实体锁超时,并有一个锁续期没有最大持续时间。),但是在调试时似乎锁定超时增加一个任意的10至15秒。我给自己定的BrokeredMessage实例的手表,我可以看到LockedUntilUtc属性格式有10-15秒加入到它的每一个我称之为RenewLock()时间。

I expected this call to give me a new lock with the same timeout as the original lock (MSDN states that "You can renew locks for the same duration as the entity lock timeout, and there is no maximum duration for a lock renewal."), but when debugging it appears that the lock timeout is increased by an 'arbitrary' 10-15 seconds. I've set a watch on the BrokeredMessage instance and I can see that the LockedUntilUtc propery has 10-15 seconds added to it every time I call RenewLock().

请问任何人都知道为什么是这样的话?可什么方法可以续约锁定更长

Does anyone know why this is the case? Can anything be done to renew the lock for longer?

编辑:

小李的回答,下面是正确的。我发现我的,其实,试图延长锁定每十秒钟的从一开始就的,即使我的代码是为了现在续签锁锁到期之前提前到20秒。这一切都归结为一个时间比较的问题,事实证明我的机器上的时间是错的(这是提前了将近一分钟)。 D'哦!

Mike's answer, below, is correct. I discovered that I was, in fact, trying to renew the lock every ten seconds right from the start even though my code was intended to renew the lock now earlier than twenty seconds prior to the lock expiring. It all came down to a time comparison issue and the fact that the time on my machine was wrong (it was ahead by nearly a minute). D'oh!

推荐答案

当你调用RenewLock它重置消息通过队列或订阅设置LockDuration锁定时间该消息是从拉动。如果你的类正在执行更新有每10-15秒射击,那么你所看到的行为是正确的。

When you call RenewLock it resets the time the message is locked by the LockDuration set on the Queue or Subscription the message is pulled from. If your class that is performing the renew has a timer that is firing every 10-15 seconds then the behavior you are seeing is correct.

例如定时器:
我有1分钟(默认值)的锁定时间的队列。结果
我拉消息的上午01点20分UTC,所以LockedUntilUtc应改为上午1点21分UTC。
如果在10秒后进入我再次呼吁在上午01时20分10秒锁定通话火灾,处理这样LockedUntilUtc将成为1:21.10 AM。

Example: I have a queue with a lock duration of 1 minute (the default).
I pull the message at 1:20 AM UTC, so the LockedUntilUtc should read 1:21 AM UTC. If 10 seconds into the processing I call Renew lock the call fires at 1:20:10 AM, so the LockedUntilUtc would become 1:21.10 AM.

有添加的锁的持续时间值与当前时刻的服务器,而不是以前的LockedUntilUtc值。这扩展了你的消息的锁定期。

It added the lock duration value to the current time at the server, not to the previous LockedUntilUtc value. This extends your period of the lock on the message.

这答案假设你经常射击定时器触发,而不是等着去接近实际的锁超时。如果你想更精确,你可以设置前被设置了锁定到期,然后进行更新锁定时器火约10-20秒。

This answer assumes you are firing the trigger on the Timer often and not waiting to get close to the actual lock timeout. If you wanted to be more precise you could set the timer to fire about 10-20 seconds before the lock is set to expire and then do the renew lock.

这篇关于为什么BrokeredMessage.RenewLock()只续签了几秒钟的锁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆