如何在 azure 函数中通过属性绑定事件中心输出参数

How in azure function bind event hub output parameter via attributes

我想使用属性将输入和输出参数绑定到事件中心。

在文档中只有关于如何使用 return 语句绑定到输出的信息 https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs#output---c-example

[FunctionName("EventHubOutput")] [return: EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")] public static string Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log) { log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); return $"{DateTime.Now}"; }

但我想使用 ICollector<EventData> outputEventHub 作为参数来得到如下内容

[FunctionName("EventHubRewriter")]
public static void Run([EventHubTrigger("samples-workitems", Connection ="EventHubInputConnectionAppSetting")] EventData[] inputMessages, ICollector<EventData> outputMessages, TraceWriter log)
{
    ...
}

如何使用输出事件中心的属性生成绑定?

更新: 以下是如何为属性绑定生成 function.json 的信息:function.json generation

几乎一模一样:

[EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")] 
ICollector<EventData> outputMessages

完整签名:

[FunctionName("EventHubRewriter")]
public static void Run(
    [EventHubTrigger("samples-workitems", Connection ="EventHubInputConnectionAppSetting")] 
    EventData[] inputMessages, 
    [EventHub("outputEventHubMessage", Connection = "EventHubConnectionAppSetting")]
    ICollector<EventData> outputMessages, 
    TraceWriter log)
{
    ...
}