My application is subscribed to an Azure service bus topic. I do some processing when the service receives a message, It works as expected when the processing time is small. But when it takes much time, my services start receiving the same message multiple times.
Exception Type: Azure.Messaging.ServiceBus.ServiceBusException
Exception Message: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. For more information please see https://aka.ms/ServiceBusExceptions . azure(MessageLockLost)
the value of MaxAutoRenewDuration
is 2 in this application. So I think if it takes more time it again gets the same message. The prefetchCount
value is 0 in the application. I have read some articles and understood that If I increase the value of MaxAutoRenewDuration
, It may solve the problem. But again I would like to know the pros and cons of it.
I have one interesting observation as well, I have added a test subscription on this topic, But this test subscription still shows only one message for this message, But my receiving application is receiving multiple messages, so how does it work?
There are two settings you need to consider in your scenario.
MaxAutoRenewDuration
LockDuration
LockDuration
is defined on the entity you receive from. It should alsway be less thanMaxAutoRenewDuration
. So if processing takes up to 5 minutes but can spike to 7, you should setLockDuration
to the max 5 minutes andMaxAutoRenewDuration
to something greater than 7.