0
votes

I am using windows azure service bus for messaging. We have created web api to pull the messages from service bus. Mobile app is using this web api for getting messages. We are using PeekLock mode in subscription client and the lockduration is 5 minutes.

On client side if messages takes more than 5 minute to process then message will unlock. So before it unlock we want to renew the Lock. So we have created another web api to renew the lock. In web api we are passing the LockToken. But when we use subscriptionClient.RenewMessageLockAsync(new Guid(lockToken)), it throws error "The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue" before the Lock expiration time. We are initiating the renew lock before 1.5 min of message LockUntilUtc time.

My question here is can we renew the message lock before it expirytime? And if yes then why azure service bus throwing lock expired error? Please help me to understand this renew lock things.

1

1 Answers

0
votes

You can extend the lock manually, but you need to make sure it happens before the server is unlocking it.

Another option, which I personally prefer more, is to use OnMessage API. It allows you to specify OnMessageOptions.AutoRenewTimeout which will be an extension time in case your callback that handles the message is not done. OnMessage API will also ensure that extension is invoked if you're about to exceed lock duration. This way you also won't need to have another web API, which sounds a little off.

Have a look at the recent post I wrote on this API.