是的,这是可能的。下面是一个 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"
}
]
}