Search code examples
azureazureservicebusazure-servicebus-queues

Azure Service Bus Queue, Stuck Messages or Incorrect Message Count?


I am using QueueDescription.MessageCount to get the number of messages remaining in one of my queue's how ever it is showing a positive number but i cannot receive any messages.

I have checked the active and deadletter queue but there is nothing to receive. I have tried to use Recieve(); RecieveBatch(); onMessage(); - All the same.

Has anyone else seen this? Are the messages stuck or is the count incorrect.

Thanks

Steve.


Solution

  • The only reason I can think of is if you have received() the message but did not call complete() or abandon(). In this case the message is "hidden" for a specific length of time (default is 30 seconds). During this time, your message count would be positive even though you cannot receive any messages.

    When 30 seconds (the default) elapses, the messages become visible and you may receive() them again. Note that the .DeliveryCount property is incremented every time you receive the message until it reaches 10 (the default) and the message is dumped into the dead-letter sub queue.

    Be sure to always call complete() on any message you have processed. Call abandon() if you want it to be immediately available in the queue for another worker to process. Also check the DeliveryCount property to be sure you are not processing a message twice. (This can happen if you take a long time processing a message before calling complete() and by then the lock has been released.)