Question

Using Azure Service Bus Topic

For exammple After 5 minutes if a try to renew a lock, it says Lock has expired message!!

What are the other options to come over it..

I have transactions that take more than 5 minutes, and after that i want to set the brokered message status to completed.

Any options?

Was it helpful?

Solution

To add to Sam's answer, if the lock duration has passed you can't renew the lock on that message. Once a lock expires the message is available to be handed out to another consumer. This means that if you were allowed to call renew lock after the lock has expired someone else may be processing that message and as far as the service bus is concerned it is already locked by that other consumer. It could be argued that it would be a "nice to have" that RenewLock would check to see if the message was already handed out again and renew if not, but it doesn't do that. If you have enough consumers and given the messages are roughly handled in order it is more likely that the message would already be off somewhere else anyway.

If you have the scenario of a unit of work taking longer than 5 minutes you'll need to manage the renewal either during your processing or on a separate thread. For example, if your processing is something where you do some work and have control flow return to your code quite often the processing thread can keep an eye on the amount of time and renew as necessary; however, it is more likely that your processing thread will be busy, in which case you'd want to have a separate thread that handles the renewal.

You might look at what your system is doing for processing and see if this could be broken up into smaller work chunks and spread across a series of queues.

OTHER TIPS

You can use the RenewLock() Method that is documented here: http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.renewlock.aspx

QueueClient queueClient = QueueClient.CreateFromConnectionString(serviceBusConnectionString, queueName);
BrokeredMessage receivedMessage = await queueClient.ReceiveAsync();
await receivedMessage.RenewLockAsync();

You can also have a look at this article on how to implement reliable messaging loops with Service Bus: http://msdn.microsoft.com/en-us/library/hh851750.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top