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

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

问题描述

我正在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应用中为队列触发器配置队列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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