Set nextVisibleTime in Azure Webjobs SDK
Asked Answered
C

2

8

I'm using Azure Webjobs to process messages from a queue.

I saw that the Webjobs SDK processes any failed message again after 10 minutes, and it if fails 5 times it moves it to the poison queue (1).

Also I can see the nextVisibleTime of the message in the queue, that is 10 minutes after the insertionTime (2).

I want to use the AzureSDK error handling of the messages but I cannot wait 10 minutes for the message to be processed again.

Is there any way I can set this nextVisibleTime to a few seconds?

Create a .NET WebJob in Azure App Service

If the method fails before completing, the queue message is not deleted; after a 10-minute lease expires, the message is released to be picked up again and processed.

How to use Azure queue storage with the WebJobs SDK

public static void WriteLog([QueueTrigger("logqueue")] string logMessage,
    DateTimeOffset expirationTime,
    DateTimeOffset insertionTime,
    DateTimeOffset nextVisibleTime,

Note: There are similar questions here in StackOverflow but with no answer:

Curbing answered 6/7, 2015 at 11:29 Comment(0)
R
5

In the latest v1.1.0 release, you can now control the visibility timeout by registering your own custom QueueProcessor instances via JobHostConfiguration.Queues.QueueProcessorFactory. This allows you to control advanced message processing behavior globally or per queue/function.

For example, to set the visibility for failed messages, you can override ReleaseMessageAsync as follows:

protected override async Task ReleaseMessageAsync(CloudQueueMessage message, FunctionResult result, TimeSpan visibilityTimeout, CancellationToken cancellationToken)
{
    // demonstrates how visibility timeout for failed messages can be customized
    // the logic here could implement exponential backoff, etc.
    visibilityTimeout = TimeSpan.FromSeconds(message.DequeueCount);

    await base.ReleaseMessageAsync(message, result, visibilityTimeout, cancellationToken);
}

More details can be found in the release notes here.

Reidreidar answered 4/12, 2015 at 17:20 Comment(0)
M
0

If there is an exception while processing your function, the SDK will put the message back in the queue instantly and the message will be reprocessed. Are you not seeing this behavior?

Mun answered 6/7, 2015 at 21:16 Comment(2)
Hi! Yes I'm seeing this behaviour, but this message will be reprocessed only after 10 minutes, as I mentioned in my question. I want to change this time to 10 seconds.Curbing
You can bind to CloudQueueMessage and set the visibility timeout as follows public static void Hi([QueueTrigger("invisible")] CloudQueueMessage message) { throw new Exception("Hi"); }Mun

© 2022 - 2024 — McMap. All rights reserved.