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

巧了我就是萌 提交于 2020-12-01 02:29:24

问题


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.


回答1:


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"
   }
}


来源:https://stackoverflow.com/questions/45776319/how-to-configure-queue-name-for-queue-trigger-in-azure-function-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!