Azure Function Queue trigger: how to set time delay for dequeue message
Asked Answered
E

1

6

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.

Evy answered 27/1, 2019 at 17:55 Comment(1)
these might help: #50818471 #39649197, found this also: learn.microsoft.com/en-us/azure/azure-functions/…. Take a look at visibilityTimeout property of the host.jsonRiggle
C
8

@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.

Colet answered 28/1, 2019 at 3:19 Comment(4)
but it set one value for all queries, I want to set different value for every caseEvy
@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.Colet
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)Evy
@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.Colet

© 2022 - 2024 — McMap. All rights reserved.