'Azure Function not triggering on Event Hub
I am pretty new to Azure and I am trying to setup a Function App that is triggered when a message is received by an Event Hub.
Here is my setup: EventHub:
Event Hubs Namespace - acc-events
Event Hub - hub
Shared Access Policy attached to hub that allows for Manage, Send, Listen
Function:
Function App - accfunction
Functions - EventHubTrigger1
Code in EventHubTrigger1:
#r "Microsoft.Azure.EventHubs"
using System;
using System.Text;
using Microsoft.Azure.EventHubs;
public static async Task Run(EventData[] events, ILogger log)
{
var exceptions = new List<Exception>();
foreach (EventData eventData in events)
{
try
{
string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count);
// Replace these two lines with your processing logic.
log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}");
await Task.Yield();
}
catch (Exception e)
{
// We need to keep processing the rest of the batch - capture this exception and continue.
// Also, consider capturing details of the message that failed processing so it can be processed again later.
exceptions.Add(e);
}
}
// Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure.
if (exceptions.Count > 1)
throw new AggregateException(exceptions);
if (exceptions.Count == 1)
throw exceptions.Single();
}
function.json:
{
"bindings": [
{
"name": "events",
"connection": "acc-events_RootManageSharedAccessKey_EVENTHUB",
"eventHubName": "hub",
"consumerGroup": "$Default",
"cardinality": "many",
"direction": "in",
"type": "eventHubTrigger"
}
]
}
When I add an event to my Event Hub the Function does not trigger.
Can anyone please let me know where I am going wrong?
This was all done via following the steps in the UI.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

