在Azure函数中如何通过属性绑定事件中心输出参数 [英] How in azure function bind event hub output parameter via attributes
问题描述
我想使用属性将输入和输出参数与事件中心绑定.
I want to bind input and output parameters from and to event hub using attributes.
在文档中,仅提供有关如何使用return
语句绑定到输出的信息
https://docs.microsoft.com/zh-CN/azure/azure-functions/functions-bindings-event-hubs#output---c-example
In a documentation there is only information how to bind to output using return
statement
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}";
}
[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
作为参数来具有以下内容
But I want to use ICollector<EventData> outputEventHub
as a parameter to have something as below
[FunctionName("EventHubRewriter")]
public static void Run([EventHubTrigger("samples-workitems", Connection ="EventHubInputConnectionAppSetting")] EventData[] inputMessages, ICollector<EventData> outputMessages, TraceWriter log)
{
...
}
如何使用输出事件中心的属性生成绑定?
更新: 以下是有关如何绑定function.json进行属性绑定的信息:
Update: Here is an info how function.json is gnerated for attribute binding: 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)
{
...
}
这篇关于在Azure函数中如何通过属性绑定事件中心输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!