Trigger Azure Functions on Event Hub

Alberto De Natale
3 min readJul 4, 2019

Azure Event Hub is one of the products offered by Azure to create event-based solutions and is focused on Big Data.

It decouples producers of events from consumers by storing the events for up to seven days. This helps to scale the application in order to fit with the different habits of the customers that are using it. Let’s say for example an application is more used during weekends, event hub supports automatical scale up and down.

An event in event up can be up to 256KB.

What an Event Is

An event:

  • Is a type of message
  • It is lightweight, that means it does carry information about what happened and not about what triggered the event. A message, on the contrary, includes intent and is part of the definition of a contract between publisher and subscriber
  • No expectations from the publisher on how the event will be handled. The consumer decides how to handle an event

Create an Event Hub Client

I have downloaded the code sample that can be found at:

Create an Event Hub

Creating an event hub instance on the portal will ask for some information like, as usual, pricing tier. For this example keeping everything basic will work fine.

Once created, I will move on the “Event Hubs” tab:

I will add a new policy

I will then copy the connection string:

Create an Event Hub .NET Core client

I have followed what’s discussed here:

And this will be the starting program:

Create a Trigger

I have configured the default trigger template that comes shipped with Visual Studio:

I added the hub connection string in the “local.settings.json” file:

You may find the following error after deploying the function “Microsoft.Azure.WebJobs.Host: Error indexing method (..) Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. Parameter name: receiverConnectionString”:

On the Publish screen, hit “Edit Azure App Service Settings”:

And set the connection string:

After running the client the following result will show on the function console:

Conclusion

Azure functions can integrate with event hub consistently as done with other products

--

--

Alberto De Natale

Alberto De Natale is a passionate tech-enthusiast software developer.