Receiving Events from an Event Hub
  • 14 Aug 2020
  • 2 Minutes To Read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Receiving Events from an Event Hub

  • Print
  • Comments
  • Share
  • Dark
    Light

#ServerlessTips - Azure Event Hubs
Author: Steef-Jan Wiggers Azure MVP

Event Hubs is a streaming and event ingestion service on the Microsoft Azure Platform capable of receiving and processing millions of events per second. The service will allow you to process and analyze the massive amounts of data produced by your connected devices and applications.

Once you have an Event Hub namespace and hub provisioned as described in the tips around creating a namespace and adding an Event Hub, you can start using Event Hubs. With programming languages such as C#, Java, or Python, you can send and receive events from an Event Hub.

When you, for instance, want to receive events from an Event Hub using C#, you can create an application (event consumer) with Visual Studio 2019 or Visual Studio Code. From with the solution you build with one of these Integrated Development Environments (IDE) you add the Azure.Messaging.EventHubs and Azure.Messaging.EventHubs.Processor .NET library (Manage NuGet).

Once you have access to the libraries in your solution, you can start writing code to receive events from an Event Hub. When writing code for receiving events, you create what is called an event consumer. For the event consumer, you will need a connection string and name of the Event Hub. Both are available in the Event Hub Namespace. From shared access policies in the Event Hub namespace, you can retrieve the connection string, and in the overview of the namespace, you can find the Event Hubs.

Furthermore, we will use Azure Storage as the checkpoint store, therefore you will need to create an Azure Storage account and blob container or leverage an existing storage account. From the storage account you can find the connection string in the access keys and the container name from the overview.

An event consumer implementation contains event processor, which simplifies receiving events from event hubs by managing persistent checkpoints and parallel receives from those event hubs. According to the Microsoft docs

An event processor is associated with a specific event Hub and a consumer group. It receives events from multiple partitions in the event hub, passing them to a handler delegate for processing using code that you provide.

Azure Event Hub Tip 6 - Picture 1

The code above shows a simple implementation of an event consumer (including event processor). When you run the application, you can verify in the Azure Portal that the application has consumed the messages.

Azure Event Hub Tip 6 - Picture 2

Note that you either write code to receive event data from an Event Hub or configure your service or application to do so.

Was This Article Helpful?