How in azure function bind event hub output parameter via attributes

杀马特。学长 韩版系。学妹 提交于 2020-02-24 14:30:38

问题


I want to bind input and output parameters from and to event hub using attributes.

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}"; }

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)
{
    ...
}

How to generate binding using attributes for the output event hub?

Update: Here is an info how function.json is gnerated for attribute binding: function.json generation


回答1:


It's almost exactly the same:

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

The full signature:

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


来源:https://stackoverflow.com/questions/49866192/how-in-azure-function-bind-event-hub-output-parameter-via-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!