0

I have Azure function running on QueueTrigger, but would like to complete the function without sending the message to poison queue if DequeueCount(max retries) exceeds the set limit (but keep sending other failed messages to the poison queue)

My current function looks like this:

public async Task ProcessThis([QueueTrigger("message-queue")] Message message, string id, string popReceipt, int dequeueCount, ILogger logger)
{
   try
   {
     ...
     //process queue here
     ...
   }
   catch (Exception e)
   {
     if (dequeueCount == this._config.DequeueCount) //Currently it's set to 10
     {
       return; //If I return here, would the message still go into poison queue?
     }

     throw e;
   } 
}

I want to know if this is the correct way to prevent the message going into poison queue if it fails due to max retry exceeds.

JNA
  • 45
  • 9

2 Answers2

2

If the function does not throw an exception, Azure Function Runtime treats that as a successfully processed message and remove it from the Q.

If you throw any sort of exception then Runtime considers it a failure and increments dequeue count. If the new count is beyond maxDequeueCount it is moved to poison Q. See doc.

So if you just don't want anything to goto poison Q, simply add a catch-all block to your ProcessThis() and suppress the exception.

Kashyap
  • 15,354
  • 13
  • 64
  • 103
0

Not sure what the max queue count is but this article has a handy work around. Just

requeue the message. You could also subscribe to the poison queue, and just requeue it

Patrick Goode
  • 1,412
  • 5
  • 20
  • 35
  • difference between re-queuing the message and throwing an exception to make Function Runtime to do it for you is that: If you re-queue using output binding the visibilityTimeout doens't apply, it's a new message. – Kashyap Jul 15 '20 at 21:15