0

I have an app where Azure functions are used for slow async tasks.

It is a c# app and the functions are declared similar to

        [FunctionName(nameof(ConfirmationEmailFunction))]
        public async Task Run([QueueTrigger(QueueNames.ConfirmationEmailQueue)] CloudQueueMessage queueMessage, ILogger log)
        {
            if (queueMessage.DequeueCount > 1)
                log.LogWarning($"Message {queueMessage.Id} has been dequeued multiple times. Message: '{queueMessage}'");

            var queueItem = JsonSerializer.Deserialize<ConfirmationEmailQueueItem>(queueMessage.AsString);

            await SendConfirmationEmail(queueItem);

        }

In the past when too many calls fail and the messages are moved to -poison queue, I used to go to "App service editor (Preview)" and go to function.json for the function I needed and added "-poison" to the binging queue name. This editor would auto-save the change and you would not need to restart the function app - it used to pick the change.

So, I didn't need to do it for a few years and now I tried it again - and the queue name changed ok, but the old non-poison queue was still used - and I could confirm it by manually adding a message to it and see it disappeared and processed.

I went to Advanced Tools -> Debug console and navifgated to the function.json and the queue is named with "-poison" in the end - which is as expected. I went to the function Integration and checked the trigger and it also has -poison in the end of the queue name.

I restarted the function app and it did not help - the old non-poison queue was still used.

So, do you know why it might stop working? Another question would be why the Azure portal shows the "...-poison" queue to be used as a trigger if the original non-poison queue is used instead?

Now, I am aware of other ways of processing the queue, but this one was super-convenient to use, you didn't need much to do and it just worked.

Mykola
  • 197
  • 1
  • 10

1 Answers1

0

Usually, If the message fails to process till its maxdequeuecount(5 tries), queuename-poison queue gets created and the message will be moved to that particular poison queue.

do you know why it might stop working

It could be because of any updates or changes in the Azure Functions runtime or configuration. Check if there are any modifications done in configurations which might be causing the issue.

Another question would be why the Azure portal shows the "...-poison" queue to be used as a trigger if the original non-poison queue is used instead?

I think this could be because the poison queue is a separate queue which is being created to store the messages which are failed to process in multiple tries. Validate if the function is configured correctly and is secure.


I have created a sample queue trigger: code snippet:

[FunctionName("Function1")]
public static async Task Run([QueueTrigger("myqueue-items", Connection = "demo")] string myQueueItem, [Queue("myqueue-items-poison", Connection = "demo")] IAsyncCollector<string> poisonQueue,
        ILogger log)
{
       try
       {             
          await ProcessMessageAsync(myQueueItem);
       }
       catch (Exception ex)
       {
       log.LogError(ex, "Failed to process message: {Message}", myQueueItem);
       await poisonQueue.AddAsync(myQueueItem);
        }
}

public static async Task ProcessMessageAsync(string myQueueItem)
{
    Console.WriteLine($"The queue message is {myQueueItem});
}  

Success response:

enter image description here

When the message fails to process, it is getting added to queuename-poison queue:

enter image description here

you can refer to the code given by Mitch Wheat to re-process the messages in poison queue.

Pravallika KV
  • 2,415
  • 2
  • 2
  • 7
  • It's not exactly what I was asking. The problem is that I used to be able to go to the App service editor, add "-poison" to the queue name in the function's json, and Azure functions runtime would just reconfigure the function to use the poison queue as a source. I don't need any code to process a poison queue - I know of multiple ways of doing so, but changing json was the easiest and the quickest. I did not need to write anything, to run anything, and pretty much to do anything - I would just change the queue name in json and the new setting would be used straight away. – Mykola Jun 01 '23 at 12:48