1

I have a TimerTrigger Azure Function which triggers every one minute. When it triggers I read a specific number of messages from my queue by this code:

cloudQueue.GetMessagesAsync(32);

And when I'm done with it I see the message gets visible in the queue again, although the function did NOT encounter any errors.

I've looked at these answers, but they all say if you have no errors in your function at runtime, messages should be removed from queue:

Azure Queue Storage triggered without removing message

Azure Function and storage queue, what to do if function fails

But my messages don't remove.

Here is my function code:

[FunctionName("MyFunctionName")]
public static async Task SchedulerFunction([TimerTrigger("0 */1 * * * *", RunOnStartup = false)]TimerInfo myTimer, [Queue("my-queue-name", Connection = "AzureWebJobsStorage")]CloudQueue cloudQueue)
{
    var messages = await cloudQueue.GetMessagesAsync(32);

    await ProcessSomethingOnMessagesWithoutAnyErrors(messages);
}

What I need is to remove the collected messages from the queue after I got them by cloudQueue.GetMessagesAsync(32); and if It fails for 3 times, then move them into my-queue-name-poison queue. If I need to use any specific RetryPolicy, don't hesitate to recommend it.

Soheil Farahani
  • 349
  • 1
  • 2
  • 13
  • Is that you want to remove the message if you have successfully processed and y remove the message to another queue after you retry it three times? – Jim Xu Sep 11 '19 at 06:15
  • @JimXu Yes, if it's processed successfully, I expect it to be removed, otherwise move it to the poison queue and this is a common practice, because we don't want some faulty messages remain in the queue after 3 failed attempts. – Soheil Farahani Sep 11 '19 at 06:18
  • Could you please provide the document you refer to? – Jim Xu Sep 11 '19 at 08:42
  • According to my research, if you want to process the message in queue, we can use queuetrigger. For more details, please refer to https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#trigger. – Jim Xu Sep 11 '19 at 09:06
  • @JimXu Thanks for the tip, I've already used QueueTrigger for other purposes, but in this case which I've asked the question, I need to process my queue every one minute, not less than a minute. You can also visit the links I've provided as reference. – Soheil Farahani Sep 11 '19 at 09:38

1 Answers1

0

If it fails for 3 times, then move them into my-queue-name-poison queue.

According to my research, Azure function timer tigger does not have retry behavior. If you cannot process one message in one trigger, your need to process it until the next time on the schedule. For more details, please refer to the document. enter image description here

What I need is to remove the collected messages from the queue after I got them by cloudQueue.GetMessagesAsync(32);

According to my test, we need to manually remove the message from the queue. The timer trigger has no way to help us complete it. So regarding the need, you need to implement it by your code.

Community
  • 1
  • 1
Jim Xu
  • 21,610
  • 2
  • 19
  • 39