1

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
Community
  • 1
  • 1
Pradeep
  • 5,101
  • 14
  • 68
  • 140
  • You forgot that line of code – James Z Jan 23 '20 at 17:22
  • @JamesZ, I added that line of code. – Pradeep Jan 27 '20 at 05:37
  • Just to confirm, you are receiving messages in the [`PeekLock`](https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock) mode right? Also, to ensure FIFO, instead of setting max delivery count to 1, you could consider using [Message Sessions](https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions). – PramodValavala Jan 27 '20 at 06:32
  • Yes I am receiving the messaged in the PeekLock mode only. I am not enable session at my queue level. – Pradeep Jan 27 '20 at 07:04
  • Using Peek() instead of Receive() won't allow you to Complete() the message. I did a mistake. Maybe it can help someone ;) – Deepak Oct 09 '20 at 18:30

1 Answers1

0

There are a few reasons why you are not able to delete the messages in Azure Service Bus Queue.

Challenge with Lock Duration

The first challenge is Time, specifically lock duration for every message once they have been retrieved. The problem is that the messages must be displayed in the UI and then provide time for the customer to choose the messages to be resubmitted or deleted. The solution would be to ask the customer to increase the lock duration, but this is not possible due to several reasons. Firstly, increasing lock duration might not be possible due to customer integration, so we cannot depend on that.

Read more on this blog post on how to overcome the challenge.

Nadeem Duke
  • 161
  • 1
  • 5