5

I have an Azure Function which listens to azure queue and, for example, something wrong. It re-adds a message to the queue again. But after 5 times message will be moved to poison queue.

I want to re-add a message to queue with a delay. For example, retry thru 1 hour. Because my Azure Function works with external resource, which can be unavailable for now. I don't want to do retry 5 times during 10 seconds at all, I want to retry after 1 hour. Of course, I write my own implementation of it, but probably this feature already exists.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
  • these might help: https://stackoverflow.com/questions/50817971/how-to-implement-exponential-backoff-in-azure-functions https://stackoverflow.com/questions/39648697/how-do-i-delay-the-execution-of-an-azure-function-after-it-fails, found this also: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#host-json. Take a look at visibilityTimeout property of the host.json – 4c74356b41 Jan 27 '19 at 17:58

1 Answers1

6

@4c74356b41 has pointed out the right way. The host.json settings for queue is what you are looking for.

visibilityTimeout is The time interval between retries when processing of a message fails maxDequeueCount is The number of times to try processing a message before moving it to the poison queue.

{
    "version": "2.0",
    "extensions": {
        "queues": {
            "visibilityTimeout" : "01:00:00",
            "maxDequeueCount": 2
        }
    }
}

If your function is v1, similarly

{
    "queues": {
      "visibilityTimeout" : "01:00:00",
      "maxDequeueCount": 2
    }
}

Update

Since the problem is mainly about changing visibilityTimeout according to specific situation, setting the delay of CloudQueue.AddMessageAsync accordingly is the only way. Actually the visibilityTimeout does exactly the same thing but on the function app level(all queue), so we don't need to insist on it in this case.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
  • but it set one value for all queries, I want to set different value for every case – Oleg Sh Jan 28 '19 at 14:30
  • 2
    @OlegSh You mean in each case the delay of dequeue is different? If so we may have to rely on your own implementation code, the configuration is on the level of whole function app, which can't be changed dynamically. – Jerry Liu Jan 28 '19 at 14:37
  • yes, I need diferent delay in each case (i.e. in place, where internal server is not available, I want to retry in 1 hour, but in place, when local DB is not updated, in 5 minutes) – Oleg Sh Jan 28 '19 at 14:43
  • 2
    @OlegSh Hmm... I think set the delay of `CloudQueue.AddMessageAsync` according to the situation is the only way. Actually the `visibilityTimeout` does exactly the same thing but on the function app level(all queue), so we don't need to insist on it in this case. – Jerry Liu Jan 28 '19 at 15:23