问题
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