Nani
Nani

Reputation: 73

How to set expiration time for queue output - Azure function js

How to set a expiration time for queue message as output in azure function

    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "myqueue",
      "connection": "AzureWebJobsStorage",
      "direction": "out"
    }
context.bindings.outputQueueItem = "message";

Upvotes: 2

Views: 463

Answers (1)

DixitArora-MSFT
DixitArora-MSFT

Reputation: 1811

I am not aware using using nodejs

But with c# , below is the sample

Change the type of your parameter to CloudQueue, then add a message manually and set the expiration time property (or rather Time To Live).

public static void Run(string input, CloudQueue outputQueue)
{
    outputQueue.AddMessage(
        new CloudQueueMessage("Hello " + input),
        TimeSpan.FromMinutes(5));
}

if your output queue name depends on request, you can use imperative binding:

public static void Run(string input, IBinder binder)
{
    string outputQueueName = "outputqueue " + input;
    QueueAttribute queueAttribute = new QueueAttribute(outputQueueName);
    CloudQueue outputQueue = binder.Bind<CloudQueue>(queueAttribute);
    outputQueue.AddMessage(
        new CloudQueueMessage("Hello " + input),
        TimeSpan.FromMinutes(5));
}

Upvotes: 2

Related Questions