I keep getting MessageLockLostExceptions
when processing messages.
One thing that is missing from your repro is the queue description. It's important to note such details as the problem you're experiencing has nothing to do with the client and is most likely either related to the broker or the underlying AMQP library.
For non-partitioned queues this setup works fine. It doesn't for partitioned queues (Standard tier). Can be observed with both the old and the new clients. I've raised a broker related issue for Azure Service Bus team to investigate.
You need to Complete
the message before the Lock Token
gets expired. Once the Lock Token is expired, you will receive MessageLockLostException
during the complete operation.
I can see that you are delaying the thread execution by 10 seconds for each message. But the messages seems to be fetched at the same point of time, that's why the remaining lock duration keeps reducing for each message.
For the fourth message, the Remaining lock duration is 00:00:00.1776760
. So, after 177 milliseconds
, the lock will expire. You are delaying the thread by 10 seconds
in the next line. So, the lock would expire and you are getting MessageLockLostException
. To avoid this exception, remove the
Delay