How to Create an Azure Event Hub

This article guides you through the process of creating an Azure Event Hub using the Azure portal, Azure CLI, and Azure Resource Manager (ARM) templates. Event Hubs is a Big Data streaming platform and event-ingestion service. It can be used to process streaming data in real time.

Prerequisites

Before you begin, you need:

  • An Azure subscription. If you don't have one, create a free account.
  • An Azure Event Hubs namespace. If you don't have one, create a namespace first. You can create a namespace using the Azure portal or Azure CLI.

Method 1: Create an Event Hub using the Azure portal

The Azure portal provides a user-friendly graphical interface for managing your Azure resources.

1

Navigate to your Event Hubs namespace in the Azure portal.

In the portal menu, select All services. In the list of resources, type Event Hubs Namespaces and select it.

Select your Event Hubs namespace from the list.

2

In the left-hand menu for the namespace, under Entities, select Event Hubs.

3

Click the + Event Hub button at the top of the Event Hubs list.

4

In the Create Event Hub pane:

  • Enter a Name for your Event Hub (e.g., myeventhub).
  • Optionally, configure the following:
    • Partition count: The number of partitions.
    • Message retention: The retention period for messages in days.
    • Auto-inflate: Enable auto-inflation for dynamic scaling.
    • Maximum throughput units: The maximum number of throughput units.
5

Click Create.

Note: The default values for partition count and message retention are usually sufficient for most use cases. You can adjust these settings later if needed.

Method 2: Create an Event Hub using Azure CLI

The Azure CLI provides a command-line interface for managing Azure resources.

First, log in to your Azure account:

az login

Then, create an Event Hub within your namespace using the following command:

az eventhubs event-group create --resource-group  --namespace-name  --name  [--partition-count ] [--message-retention ]

Replace the placeholders:

  • <YourResourceGroupName>: The name of your resource group.
  • <YourNamespaceName>: The name of your Event Hubs namespace.
  • <YourEventHubName>: The desired name for your Event Hub.
  • <PartitionCount> (Optional): The number of partitions.
  • <MessageRetentionInDays> (Optional): The message retention period in days.
Tip: To find your resource group and namespace names, use az eventhubs namespace list.

Method 3: Create an Event Hub using an ARM Template

Azure Resource Manager (ARM) templates allow you to define your infrastructure as code.

Here's a sample ARM template to create an Event Hub:


{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "namespaceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the Event Hubs namespace"
            }
        },
        "eventHubName": {
            "type": "string",
            "metadata": {
                "description": "Name of the Event Hub"
            }
        },
        "partitionCount": {
            "type": "int",
            "defaultValue": 4,
            "metadata": {
                "description": "The partition count for the Event Hub"
            }
        },
        "messageRetentionInDays": {
            "type": "int",
            "defaultValue": 7,
            "metadata": {
                "description": "The message retention in days for the Event Hub"
            }
        }
    },
    "resources": [
        {
            "type": "Microsoft.EventHub/namespaces/eventhubs",
            "apiVersion": "2021-11-01",
            "name": "[concat(parameters('namespaceName'), '/', parameters('eventHubName'))]",
            "properties": {
                "partitionCount": "[parameters('partitionCount')]",
                "messageRetentionInDays": "[parameters('messageRetentionInDays')]"
            }
        }
    ]
}
                                

To deploy this template, you can use the Azure CLI:

az deployment group create --resource-group  --template-file  --parameters namespaceName= eventHubName=

Next Steps

After creating your Event Hub, you can start sending and receiving events. Refer to the following articles for more information: