Creating an Azure Event Hub

This guide walks you through the steps to create an Azure Event Hub using the Azure portal, Azure CLI, and Azure SDKs.

Prerequisites

Method 1: Using the Azure Portal

The Azure portal provides a user-friendly interface for creating and managing Event Hubs.

Step 1: Navigate to Event Hubs

1. Sign in to the Azure portal.

2. In the search bar at the top, enter "Event Hubs" and select "Event Hubs" from the search results.

3. Click on + Create to start creating a new Event Hubs namespace.

Step 2: Configure the Event Hubs Namespace

1. On the "Create namespace" page, select your Azure subscription and resource group.

2. Enter a unique name for your Event Hubs namespace. The name must be globally unique.

3. Select a region for your namespace.

4. Choose a Pricing tier (Basic, Standard, or Premium).

5. Click Review + create, and then click Create.

Step 3: Create an Event Hub

1. Once the namespace is deployed, navigate to its resource page.

2. In the left-hand menu, under "Entities", click on Event Hubs.

3. Click on + Event Hub.

4. Enter a name for your Event Hub.

5. Configure settings like Partition count and Message retention.

6. Click Create.

Important: Partition Count

The partition count determines the parallelism of your Event Hub. Higher partition counts allow for greater throughput but also increase complexity. Choose a count that aligns with your expected event volume and consumer parallelism.

Method 2: Using Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for scripting and automating Azure resource management.

First, ensure you have the Azure CLI installed and are logged in:

az login

Step 1: Create an Event Hubs Namespace

Replace placeholders with your actual values.

az eventhubs namespace create --resource-group  --name  --location  --sku Standard

Step 2: Create an Event Hub

Replace placeholders with your actual values.

az eventhubs eventhub create --resource-group  --namespace-name  --name  --partition-count 4 --message-retention-in-days 7

Tip: Listing Resources

You can list your Event Hubs namespaces and event hubs using:

az eventhubs namespace list --resource-group 
az eventhubs eventhub list --resource-group  --namespace-name 

Method 3: Using Azure SDKs

For programmatic creation, you can use Azure SDKs available for various languages.

Example using .NET SDK

Install the necessary NuGet package:

dotnet add package Azure.ResourceManager.EventHubs

C# Code Snippet:


using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.EventHubs;
using Azure.ResourceManager.EventHubs.Models;
using System;
using System.Threading.Tasks;

// ...

async Task CreateEventHubAsync(string subscriptionId, string resourceGroupName, string namespaceName, string eventHubName)
{
    ArmClient client = new ArmClient(new DefaultAzureCredential());
    SubscriptionResource subscription = client.GetDefaultSubscription();

    // Get or create resource group
    ResourceGroupResource resourceGroup = (await subscription.GetResourceGroups().GetAsync(resourceGroupName)).Value;

    // Create Event Hubs namespace
    var nsData = new EventHubNamespaceData(new AzureLocation("eastus"))
    {
        Sku = new EventHubsSku(EventHubsSkuName.Standard)
    };
    ArmOperation<EventHubNamespaceResource> nsOperation = await resourceGroup.GetEventHubNamespaces().CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, nsData);
    EventHubNamespaceResource eventHubNamespace = nsOperation.Value;

    // Create Event Hub
    var ehData = new EventHubResourceData()
    {
        PartitionCount = 4,
        MessageRetentionInDays = 7
    };
    ArmOperation<EventHubResource> ehOperation = await eventHubNamespace.GetEventHubs().CreateOrUpdateAsync(WaitUntil.Completed, eventHubName, ehData);
    EventHubResource eventHub = ehOperation.Value;

    Console.WriteLine($"Event Hub '{eventHub.Id.Name}' created successfully in namespace '{eventHubNamespace.Id.Name}'.");
}
            

Similar examples are available for Python, Java, and JavaScript.

Next Steps

Once your Event Hub is created, you can start sending and receiving events. Explore the following resources: