I have a single function in an Azure Function App written in NodeJS which is an Event Hub Trigger and is used to forward logs to datadog. The logs are generated as events to event hub then getting captured by event hub trigger azure function and then pushed to datadog using rest endpoints. If my function.json file looks like this, my function app works fine:
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "eventHubMessages1",
"direction": "in",
"eventHubName": "general",
"connection": "EVENTHUB_CONN_STR",
"cardinality": "many",
"consumerGroup": "$Default"
}
],
"disabled": false
}
However, when I add one more event hub, the function app stops working.
{
"bindings": [
{
"type": "eventHubTrigger",
"name": "eventHubMessages1",
"direction": "in",
"eventHubName": "general",
"connection": "EVENTHUB_CONN_STR",
"cardinality": "many",
"consumerGroup": "$Default"
},
{
"type": "eventHubTrigger",
"name": "eventHubMessages2",
"direction": "in",
"eventHubName": "insights-logs-auditevent",
"connection": "EVENTHUB_CONN_STR",
"cardinality": "many",
"consumerGroup": "$Default"
}
],
"disabled": false
}
Is it possible for same function to get triggered by multiple event hubs present in the same event hub namespace? If yes, how can I do that?
It is not feasible to trigger a single function with multiple event hubs but a function can have multiple input/output binding. Refer to this SO Thread which says the same.
If you want to use two different event hubs then you need to create two event hub triggers functions (use func new command to create the second function) and your folder structure should look like below-
In this way, you can consume two event hubs.