问题
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