0
votes

I have created an event hub triggered function app, which would received from one event hub and send message/data to another event hub using

public static async Task Run(
    [EventHubTrigger("source", Connection = "EventHubConnectionAppSetting")] EventData[] events,
    [EventHub("dest-1", Connection = "EventHubConnectionAppSetting")]IAsyncCollector<string> outputEvents,
    ILogger log)

however, right now I would like to publish the same message to one or more additional event hubs(e.g, dest-2, dest-3, etc) so all my consumer event hubs(dest-1, dest-2, dest-3) could consume same message async. Is there anyway to achieve that approach with Azure Event hub triggered function app?

1

1 Answers

1
votes

If you don't want to create multiple async collectors then You need to use custom binder with IBinder class. Like below.

public static async Task Run(
    [EventHubTrigger("source", Connection = "EventHubConnectionAppSetting")] EventData[] events,
    IBinder binder,
    ILogger log) {

    // custom binding here (exmaple)
    var collector = await binder.BindAsync<IAsyncCollector<string>>(
                    new EventHubAttribute(... params to event hub here...));

    var message = ...
    await collector.AddAsync(message);

}

I typed this from my phone so sorry if there are typos ;) But in general this is a way to go.