Configure applications to send or receive messages through an Event Hub

After you have created and configured your Event Hub, you'll need to configure applications to send and receive event data streams.

For example, a payment processing solution will use some form of sender application to collect customer's credit card data and a receiver application to verify that the credit card is valid.

Although there are differences in how a Java application is configured, compared to a .NET application, there are general principles for enabling applications to connect to an Event Hub, and to successfully send or receive messages. So, although the process of editing Java configuration text files is different to preparing a .NET application using Visual Studio, the principles are the same.

What are the minimum Event Hub application requirements?

To configure an application to send messages to an Event Hub, you must provide the following information, so that the application can create connection credentials:

  • Event Hub namespace name
  • Event Hub name
  • Shared access policy name
  • Primary shared access key

To configure an application to receive messages from an Event Hub, provide the following information, so that the application can create connection credentials:

  • Event Hub namespace name
  • Event Hub name
  • Shared access policy name
  • Primary shared access key
  • Storage account name
  • Storage account connection string
  • Storage account container name

If you have a receiver application that stores messages in Azure Blob Storage, you'll also need to first configure a storage account.

Azure CLI commands for creating a general-purpose standard storage account

The Azure CLI provides a set of commands you can use to create and manage a storage account. We'll work with them in the next unit, but here's a basic synopsis of the commands.

Tip

There are several MS Learn modules that cover storage accounts, starting in the module Introduction to Azure Storage.

Command Description
storage account create Create a general-purpose V2 Storage account.
storage account key list Retrieve the storage account key.
storage account show-connection-string Retrieve the connection string for an Azure Storage account.
storage container create Creates a new container in a storage account.

Shell command for cloning an application GitHub repository

Git is a collaboration tool that uses a distributed version control model, and is designed for collaborative working on software and documentation projects. Git clients are available for multiple platforms, including Windows, and the Git command line is included in the Azure Bash cloud shell. GitHub is a web-based hosting service for Git repositories.

If you have an application that is hosted as a project in GitHub, you can make a local copy of the project, by cloning its repository using the git clone command. We'll do this in the next unit.

Editing files in the Cloud SHell

You can use one of the built-in editors in the Cloud Shell to modify all the files that make up the application and add your Event Hub namespace, Event Hub name, shared access policy name, and primary key.

The Cloud Shell supports nano, vim and emacs as well as a Visual Studio Code-like editor named code. Just type the name of the editor you want and it will launch in the environment. We'll use the code editor in the next unit.

Summary

Sender and receiver applications must be configured with specific information about the Event Hub environment. You create a storage account if your receiver application stores messages in Blob Storage. If your application is hosted on GitHub, you have to clone it to your local directory. Text editors, such as nano are used to add your namespace to the application.