DEV Community

Kenichiro Nakamura
Kenichiro Nakamura

Posted on

5 2

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.

Get Event Hub message content

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]}");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

input argument contains message from EventHub.
image

How about EventData?

We can get EventData from FunctionContext. I don't feel this is ideal way to obtain data, but we can get it anyway.

image

There is a GitHub issue for this as well.
https://github.com/Azure/azure-functions-dotnet-worker/issues/283

Summary

I hope we can switch signature from string[] to EventData like we did in previous version, but this is how it works for now.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs