2

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://learn.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 Answer 1

3

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)
{
    ...
}    
Sign up to request clarification or add additional context in comments.

8 Comments

I thought it is like that. But after deploy it generates me function.json as below: ` { "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6", "configurationSource": "attributes", "bindings": [ { "type": "eventHubTrigger", "connection": "EventHubInputConnectionAppSetting", "path": "output", "name": "eventDataSet" } ], "disabled": false, "scriptFile": "../bin/EventHub.dll", "entryPoint": "EventHub.Ordered.Run" } `
@wolszakp That's ok. Input/Output bindings are not included into auto-generated function.json
Ok thanks for an explanation. But what's a reason to use this attributes - I thought that thanks to this attributes function.json will be automatically generated.
@wolszakp Runtime will use the attribute directly, skipping function.json sectuon
I meant what is in documentation: Ok thanks for an explanation. But what's a reason to use this attributes - I thought that thanks to this attributes function.json will be automatically generated. I am pointing what is in documentation: learn.microsoft.com/en-us/azure/azure-functions/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.