C# 如何基于函数触发器中的属性绑定azure函数输入?

C# 如何基于函数触发器中的属性绑定azure函数输入?,c#,azure,azure-functions,C#,Azure,Azure Functions,我想创建一个由事件中心消息触发的Azure函数。我还想使用DocumentDb中的文档,从触发器消息(事件中心消息)的内容中获取DocumentId。 我不知道这是怎么可能的,我怀疑它是否是,但我想尝试一下。 在输入中,我选择了DocumentDB,在DocumentId输入框(默认为{DocumentId})中,我输入了{MyEventThubMessage.DocumentId},其中MyEventThubMessage是我的触发器的名称,DocumentId是消息内容中的json属性 知道

我想创建一个由事件中心消息触发的Azure函数。我还想使用DocumentDb中的文档,从触发器消息(事件中心消息)的内容中获取DocumentId。 我不知道这是怎么可能的,我怀疑它是否是,但我想尝试一下。 在输入中,我选择了DocumentDB,在DocumentId输入框(默认为{DocumentId})中,我输入了{MyEventThubMessage.DocumentId},其中MyEventThubMessage是我的触发器的名称,DocumentId是消息内容中的json属性


知道这是否可能,以及我如何解决这个问题(在我的函数中没有硬编码DocDb连接字符串)是的,这是可能的。下面是一个C#示例,首先显示代码,然后显示绑定元数据。对于其他语言,如Node,绑定元数据将是相同的,只是代码不同。DocumentDB绑定通过绑定表达式{DocId}绑定到传入消息的DocId属性

代码如下:

#r "Microsoft.ServiceBus"

using System;
using Microsoft.ServiceBus.Messaging;

public static void Run(MyEvent evt, MyDocument document, TraceWriter log)
{
    log.Info($"C# Event Hub trigger function processed event: {evt.Id}");
    log.Info($"Document {document.Id} loaded. Value {document.Value}");
}

public class MyEvent
{
    public string Id { get; set; }
    public string DocId { get; set; }
}

public class MyDocument
{
    public string Id { get; set; }
    public string Value { get; set; }
}
以及绑定元数据:

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "evt",
      "direction": "in",
      "path": "testhub",
      "connection": "<your connection>"
    },
    {
      "type": "documentdb",
      "name": "document",
      "databaseName": "<your database>",
      "collectionName": "<your collection>",
      "id": "{DocId}",
      "connection": "<your connection>",
      "direction": "in"
    }
  ]
}
{
“绑定”:[
{
“类型”:“eventHubTrigger”,
“名称”:“evt”,
“方向”:“在”,
“路径”:“测试中心”,
“连接”:”
},
{
“类型”:“documentdb”,
“名称”:“文件”,
“数据库名称”:“,
“collectionName”:“,
“id”:“{DocId}”,
“连接”:“,
“方向”:“in”
}
]
}

英雄!你救了我一天