39

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.

Steviebob
  • 1,705
  • 2
  • 23
  • 36
  • I suggest you implement the INameResolver interface. https://stackoverflow.com/questions/44901165/azure-function-flexible-test-and-production-queue-names – camelCase Aug 19 '17 at 22:20

1 Answers1

96

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"
   }
}
Garth Mason
  • 7,611
  • 3
  • 30
  • 39
  • How does this translate to an azure deployment i.e. where do I set MyQueueName to have it picked up once deployed? And similarly for the connection string 'testdelete'? – Taran May 21 '18 at 20:39
  • 2
    I haven't worked with these settings for a while now, but from memory they are in the AppSettings of the function app - so it depends on how you are publishing the function app (settings might be in an ARM template) – Garth Mason May 22 '18 at 06:42
  • 2
    @Taran, you can place these into your Application Settings of your Function App – Wah Yuen May 22 '18 at 06:45
  • 2
    This actually works! Also if you want to override these settings in azure portal appsettings tab then you don't need to write parent setting name Values:MyQueueName , just only: MyQueueName. – Dainius Kreivys Jan 19 '19 at 13:13
  • 1
    so how would you do this if for example you are using nodejs and have to work witht he `function.json` file? – Alex Gordon Aug 21 '19 at 19:26
  • 2
    Is this documented anywhere so I can read more about it? – Crhistian Ramirez Mar 05 '21 at 03:25
  • 3
    @CrhistianRamirez the Microsoft documentation is [here](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-expressions-patterns#binding-expressions---app-settings) – David Yates May 12 '21 at 20:16