This folder contains a Java application example that handles Event Hubs on Microsoft Azure.
It handles an Event Hub and send events to an event hub event stream.
-
You must have a Microsoft Azure subscription.
-
You must have the following installed:
- Java Development Kit (JDK) 8
- Apache Maven 3
- Azure CLI
-
The code was written for:
- Java 8
- Apache Maven 3
- Azure SDK for Java: New Client Libraries (Azure Event Hub library v5) (com.azure)
-
# Azure (Interactively).
The Azure CLI's default authentication method for logins uses a web browser and access token to #.
-
Run the Azure CLI login command.
az login
If the CLI can open your default browser, it will do so and load an Azure sign-in page.
Otherwise, open a browser page at https://aka.ms/devicelogin and enter the authorization code displayed in your terminal.
If no web browser is available or the web browser fails to open, use device code flow with az login --use-device-code.
-
# with your account credentials in the browser.
Make sure you select your subscription by:
az account set --subscription <name or id>
-
-
Create an Event Hubs Namespace and an Event Hub.
-
Create an Event Hubs Namespace.
An Event Hubs namespace provides a unique scoping container, in which you create one or more event hubs.
To create a namespace in your resource group using the portal, do the following actions:
-
You must create the Event Hubs Namespace, using the Azure console.
-
Select the your data for: Suscription, Resource group, Namespace name and Location.
-
Choose Basic for the # tier.
-
-
Create an Event Hub.
You must create the Event Hub, using the Azure console.
To create an event hub within the namespace, do the following actions:
-
On the Event Hubs Namespace page, select
Event Hubs
in the left menu. -
At the top of the window, select
+ Event Hub
. -
Type a name for your event hub, then select
Create
.
-
-
Create a SAS Policy.
You must create the SAS Policy, using the Azure console.
-
On the Event Hubs page for the Event Hub created, select
Shared access policies
in the left menu. -
At the top of the window, select
+ Add
. -
Type a name for your Policy, select
Manage
, that includesSend
andListen
, then selectCreate
.
-
-
-
Configure your application.
The configuration is stored in the
app.properties
properties file, located in the pathsrc/main/resources
. The file content is:EventHubConnectionString=<EVENT_HUB_CONNECTION_STRING> EventHubName=<EVENT_HUB_NAME>
You must edit the file
app.properties
and replace the values of:<EVENT_HUB_CONNECTION_STRING>
by the Connection string for the Event Hub.<EVENT_HUB_NAME>
by the name of the Event Hub.
The application uses this information for accessing your Event Hub.
-
Run the code.
Execute the java application:
java -jar azureeventhubsendevent.jar
You should see the next message:
Preparing batch of events ... Sending batch of events to Event Hub ... Sent
-
Test the application.
The events should be in the Event Hub.