【问题标题】:Azure function with additional input data parameter binding具有附加输入数据参数绑定的 Azure 函数
【发布时间】:2017-11-14 04:38:36
【问题描述】:

我正在尝试使用 ServiceBus 队列触发器和其他输入数据创建 Azure 函数。 也就是说,该函数应在 blob 更新时触发,并将 blob 名称作为输入。我想要一个 Blob 数据作为附加输入。

创建的function.json如下。

{
  "bindings": [
    {
      "name": "myQueueItem",
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "afqueue",
      "connection": "CONNECTIONSTRING",
      "accessRights": "Listen"
    },
    {
      "type": "blob",
      "name": "inputBlob",
      "path": "samplecontainer/{name}",
      "connection": "AzureWebJobsDashboard",
      "direction": "in"
    }
  ],
  "disabled": false
}

定义的函数签名如下。

public static void Run(string myQueueItem, Stream inputBlob, TraceWriter log){}

这会产生如下错误

Function ($ServiceBusQueueTriggerCSharp1) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ServiceBusQueueTriggerCSharp1'. Microsoft.Azure.WebJobs.Host: No binding parameter exists for 'name'.

如果给定硬编码值而不是参数 {name},则该函数正常工作。 如何绑定输入数据变量。

【问题讨论】:

    标签: c# azure azure-functions serverless


    【解决方案1】:

    输入绑定可以从触发器参数模板化。因此,name 应该是您的服务总线消息有效负载的一部分。你可以像这样实现这个函数:

    public class MyQueueItem
    {
        public string name { get; set; }
    }
    
    public static void Run(MyQueueItem myQueueItem, Stream inputBlob, TraceWriter log)
    {}
    

    请注意,此功能的唯一触发器是服务总线消息。该功能不会由 blob 更新触发,除非您的某些其他代码为系统中的每个更新发送带有 blob 名称的服务总线消息。

    【讨论】:

    • 干杯!这行得通。我找不到足够的文档。
    • unless some other code of yours sends a Service Bus message with blob name for each update in the system - 对于存储队列,我的经验是,无论接收到的消息类型如何 - 即使指定强类型对象,例如使用 MyQueueItem - 触发器仍然触发!你不同意吗?
    • 不确定您关于存储队列的问题与我的回答有何关联
    猜你喜欢
    • 1970-01-01
    • 2014-03-24
    • 2021-04-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    相关资源
    最近更新 更多