如何在 Azure Function App 中为队列触发器配置队列名称 [英] How To Configure Queue Name for Queue Trigger In Azure Function App

查看:21
本文介绍了如何在 Azure Function App 中为队列触发器配置队列名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Azure 中创建一个函数应用,并且想要使用队列触发器.我知道如何在设计时配置队列名称,例如:

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)

但是,我希望能够在配置文件中定义和引用它.我知道function.json(可能是这个)、host.json和local.settings.json的存在,但我不知道如何在其中设置队列名称并在函数中引用它.

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.

如果我部署在 Visual Studio 中创建的新创建的函数(使用新的 15.3 更新),我可以在部署后的 function.json 文件中看到以下内容(即使我在本地开发时该文件不存在):

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

我发现如果我创建该文件,并将queueName"更改为与实际函数中的值不匹配的值,不幸的是它不会覆盖它(我猜这太容易了).

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).

如何在函数 QueueTrigger 属性中引用 function.json 中的绑定?

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).

谢谢.

推荐答案

您不能只引用队列名称作为您的 App Function 的设置(使用 %settingName% 语法)吗?然后在您部署的每个函数应用中将设置更改为所需的队列名称.

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)

并在local.settings.json中指定设置以在本地运行

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

{
  "Values: {
     "MyQueueName": "myqueue-items"
   }
}

这篇关于如何在 Azure Function App 中为队列触发器配置队列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆