I have a function that adds messages to a queue using queueCollector.AddAsync(message).
I would like to set a VisibilityTimeout per message. How can it be done?
I have a function that adds messages to a queue using queueCollector.AddAsync(message).
I would like to set a VisibilityTimeout per message. How can it be done?
Looks like your function uses IAsyncCollector<T>
as output type. With this output binding, we can only output message body and properties like visibilityTimeout are set by Azure Storage Service automatically.
To control the properties of CloudQueueMessage, we could use CloudQueue
as output type, i.e. binding to the Queue directly. Note that visibilitytimeouot can't be larger than 7 days.
C# pre-compiled code sample, use queue trigger and output message.
public static async Task Run([QueueTrigger("queue-in")]string message, ILogger log,
[Queue("queue-out")]CloudQueue outQueue)
{
// set 3 minutes visibility timeout after being created in the queue
await outQueue.AddMessageAsync(new CloudQueueMessage(message), null, TimeSpan.FromMinutes(3), null, null);
}
C# scripts sample for online development.
#r "Microsoft.WindowsAzure.Storage"
using System;
using Microsoft.WindowsAzure.Storage.Queue;
public static async Task Run(string message, ILogger log, CloudQueue outQueue)
{
log.LogInformation($"C# Queue trigger function processed: {message}");
await outQueue.AddMessageAsync(new CloudQueueMessage(message), null, TimeSpan.FromMinutes(3), null, null);
}
Its function.json
{
"bindings": [
{
"name": "message",
"type": "queueTrigger",
"direction": "in",
"queueName": "queue-in",
"connection": "MyStorageConnection"
},
{
"type": "queue",
"name": "outQueue",
"queueName": "queue-out",
"connection": "MyStorageConnection",
"direction": "out"
}
]
}
There's another visibilityTimeout in host.json. If you want to set the time interval between retries when processing of a message fails, have a look at it.