Azure function: set infinite TTL when adding a message to a queue

Fabio 26 Reputation points
2020-08-09T17:09:28.157+00:00

Hi,

I've created an Azure Function having an HTTP trigger and an Azure Queue Storage as output.

The function simply add a new message to the Queue.

It's possible to set the Expiration Time TTL to infinite (-1) when the message is added to the queue?

I've followed the procedure described in this link: en-us/azure/azure-functions/functions-integrate-storage-queue-output-binding?tabs=csharp but I cannot see how to specify the Expiration time.

Thanks

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,978 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
105 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,421 Reputation points
    2020-08-10T06:26:20.53+00:00

    Hi @Fabio

    You need to update the output binding. For C# you can use the CloudQueue as per the below code.
    To set up the TTL as infinite you need to use the overloaded method and set timeToLive parameter to maximum value i.e. TimeSpan.MaxValue. Other parameters you can set according to your business needs.
    Reference: https://video2.skills-academy.com/en-us/azure/azure-functions/functions-bindings-storage-queue-output?tabs=csharp#usage

    16569-image.png

            public static async Task QueueOutputAsync([HttpTrigger] HttpRequest input, [Queue("<yourqueuename>")] CloudQueue outputQueue)  
            {  
                await outputQueue.AddMessageAsync(new CloudQueueMessage("<your message>"),TimeSpan.MaxValue,TimeSpan.FromSeconds(0),new QueueRequestOptions(),new OperationContext());  
            }  
    

    Please 'Accept as answer' if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.