1

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?

MichalO
  • 37
  • 6

1 Answers1

1

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.

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Should I do it in code? Isn't AutoRenewTimeout for that? – MichalO Apr 12 '17 at 11:23
  • Can you share a link for `AutoRenewTimeout`? I was not able to find this property. – Gaurav Mantri Apr 12 '17 at 11:28
  • It's a field in [OnMessageOptions](https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.onmessageoptions?view=azureservicebus-4.0.0) class. Here is a topic about it: http://stackoverflow.com/questions/36561227/azure-servicebus-autorenewtimeout – MichalO Apr 12 '17 at 11:38
  • Is it possible to use RenewLock from other thread then one processing message? In my case, during processing message I'm calling some scripts on remote server and it takes more then 5 minutes. So I can't call RenewLock in this thread. – MichalO Apr 19 '17 at 13:30
  • 1
    To renew lock you would need message id and lock token. As long as you're able to provide the other thread this information, I don't see any reason why you can't accomplish the same in the other thread. – Gaurav Mantri Apr 19 '17 at 13:48