Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Configure Queue Name for Queue Trigger In Azure Function App

I'm creating a function app in Azure and want to use a queue trigger. I know how to configure the queue name at design time, e.g:

[FunctionName("MyTestFunction")]  public static void Run([QueueTrigger("myqueue-items", Connection = "testdelete")]string myQueueItem, TraceWriter log)

However, I'd like to be able to define and reference it in a configuration file. I'm aware of the existence of function.json (Probably this one), host.json and local.settings.json, but I don't know how to set a queue name in there and have it be referenced in the function.

If I deploy a freshly created function created in visual studio (With the new 15.3 update), I can see the following in the function.json file post deployment (even though the file doesn't exist when i develop locally):

  "bindings": [      {        "type": "queueTrigger",        "queueName": "myqueue-items",        "connection": "testdelete",        "name": "myQueueItem"      }

I've found that if I create that file, and change the "queueName" to something that doesn't match the value in the actual function, it unfortunately doesn't override it (That would have been too easy I guess).

How can I reference the bindings in the function.json in the functions QueueTrigger attribute?

Presumably whatever the solution is will allow me to do the same with poison queue handling?

The reason I want to do this, is because I need to deploy multiple instances of the exact same function, but pointing each one at a different queue (In order to get around max memory limitations).

Thanks.

like image 216
Steviebob Avatar asked Aug 19 '17 21:08

Steviebob


People also ask

What are queue triggers?

Use the queue trigger to start a function when a new item is received on a queue. The queue message is provided as input to the function. A C# function can be created using one of the following C# modes: In-process class library: compiled C# function that runs in the same process as the Functions runtime.

How do I trigger Azure function from the service bus queue?

Use the ServiceBusReceivedMessage type to receive message metadata from Service Bus Queues and Subscriptions. To learn more, see Messages, payloads, and serialization. In C# class libraries, the attribute's constructor takes the name of the queue or the topic and subscription.


1 Answers

Could you not just reference the queue name as a setting (using the %settingName% syntax) for your App Function? Then in each function app you deploy have change the setting to the required queue name.

[FunctionName("MyTestFunction")] public static void Run([QueueTrigger("%MyQueueName%", Connection = "testdelete")]string myQueueItem, TraceWriter log) 

And specify the setting in local.settings.json for running locally

{   "Values: {      "MyQueueName": "myqueue-items"    } } 
like image 165
Garth Mason Avatar answered Oct 23 '22 21:10

Garth Mason