18
Azure Function and .NET 5: How to get EventData for Event Hub input binding
How binding works in .NET 5 version of Azure Function changed slightly compared to last version. In this article, I explain how you can get
EventData
for Event Hub input binding.This is template code and you can see the message comes in as string array.
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace eventhubbinding
{
public static class eventhubtriggerdemo
{
[Function("eventhubtriggerdemo")]
public static void Run([EventHubTrigger("samples-workitems", Connection = "")] string[] input, FunctionContext context)
{
var logger = context.GetLogger("eventhubtriggerdemo");
logger.LogInformation($"First Event Hubs triggered message: {input[0]}");
}
}
}
We can get EventData from FunctionContext. I don't feel this is ideal way to obtain data, but we can get it anyway.

There is a GitHub issue for this as well.
https://github.com/Azure/azure-functions-dotnet-worker/issues/283
https://github.com/Azure/azure-functions-dotnet-worker/issues/283
I hope we can switch signature from string[] to EventData like we did in previous version, but this is how it works for now.