MichalO
MichalO

Reputation: 37

Azure Service Bus and long processing messages

In my system LockDuration = 5 minutes, AutoRenewTimeout = 20 minutes. Processing of some messages taking more then 5 minutes (sometime 5:15, sometimes more then 6:00). For these messages I have an exception:

"The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue."

I read in our logs, that system started processing a message (lets call it Process_A), it was still in progress when, after 5 minutes, system start processing the same message one more time (lets call it Process_B). Process_A finished and called Complete(). Then Process_B did the work and called Complete(). And it causes exception because this message is already complited.

I found in documentation that maximum value of LockDuration is 5 minutes. Why? Messages lasting more than 5 minutes can't be processed? Or mayby the configuration is wrong?

Upvotes: 1

Views: 2455

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136366

The solution would be to renew the lock on the message in case time to process the message is taking more than the maximum lock duration. If you're using Azure Service Bus .Net SDK, the method you would want to call is RenewMessageLock and pass in the lock id you received when you fetched the message.

You may also find this blog post helpful: http://vunvulearadu.blogspot.in/2015/09/azure-service-bus-how-to-extend-lock-of.html.

Upvotes: 1

Related Questions