I am using Azure Service Bus Queues in one of my .net core application to receive the messages from the Queue in the FIFO order. Once received the message from the Queue, then I have processed the business logic with each message. Once processed the business logic with each message then I am trying to delete the message from Queue with following line of code:
await _messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
But for the few messages, I am unable to delete the messages from Queue. Because lock on the message expired even though I configured the “Lock Duration” 3 minutes on Service Bus Queue.
I am getting the following error while deleting/completing the message from Service Bus Queue:
Exception Type: System.InvalidOperationException
Exception Message: Operation is not valid due to the current state of the object.
These are properties I configured on the Azure Service Bus Queue:
Max Delivery Count =1
Lock Duration=3 minutes