Bird
Raised Fist0
Azurecloud~5 mins

Event Hubs for streaming data in Azure - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Event Hubs lets you collect and process large streams of data in real time. It solves the problem of handling many messages from devices or apps quickly and reliably.
When you want to collect sensor data from many devices at once.
When you need to process logs or telemetry from multiple servers in real time.
When you want to build a live dashboard that updates as new data arrives.
When you need to send data streams to analytics or storage systems continuously.
When you want to decouple data producers and consumers for better scalability.
Config File - eventhub_namespace.bicep
eventhub_namespace.bicep
param location string = 'eastus'
param eventHubNamespaceName string = 'example-eh-namespace'
param eventHubName string = 'example-eventhub'

resource eventHubNamespace 'Microsoft.EventHub/namespaces@2022-10-01-preview' = {
  name: eventHubNamespaceName
  location: location
  sku: {
    name: 'Standard'
    tier: 'Standard'
    capacity: 1
  }
  properties: {
    isAutoInflateEnabled: false
    maximumThroughputUnits: 0
  }
}

resource eventHub 'Microsoft.EventHub/namespaces/eventhubs@2022-10-01-preview' = {
  name: '${eventHubNamespaceName}/${eventHubName}'
  properties: {
    messageRetentionInDays: 1
    partitionCount: 2
  }
  dependsOn: [eventHubNamespace]
}

This Bicep file creates an Event Hubs namespace and an Event Hub inside it.

eventHubNamespace: The container for your Event Hubs, with a Standard pricing tier.

eventHub: The actual Event Hub that receives streaming data, with 2 partitions and 1 day retention.

Commands
This command deploys the Event Hubs namespace and Event Hub to the Azure resource group named example-rg using the Bicep template.
Terminal
az deployment group create --resource-group example-rg --template-file eventhub_namespace.bicep
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded", "outputs": {} } }
→
--resource-group - Specifies the Azure resource group to deploy to
→
--template-file - Specifies the Bicep template file to use for deployment
This command checks the details of the Event Hub to confirm it was created successfully.
Terminal
az eventhubs eventhub show --resource-group example-rg --namespace-name example-eh-namespace --name example-eventhub
Expected OutputExpected
{ "name": "example-eventhub", "partitionCount": 2, "messageRetentionInDays": 1, "status": "Active" }
→
--resource-group - Specifies the resource group where the Event Hub exists
→
--namespace-name - Specifies the Event Hubs namespace name
→
--name - Specifies the Event Hub name
This command creates a consumer group to read data from the Event Hub, allowing multiple independent readers.
Terminal
az eventhubs eventhub consumer-group create --resource-group example-rg --namespace-name example-eh-namespace --eventhub-name example-eventhub --name example-consumer-group
Expected OutputExpected
{ "name": "example-consumer-group", "userMetadata": null }
→
--eventhub-name - Specifies the Event Hub to create the consumer group for
→
--name - Specifies the consumer group name
This command retrieves the connection string needed to send or receive data from the Event Hub.
Terminal
az eventhubs namespace authorization-rule keys list --resource-group example-rg --namespace-name example-eh-namespace --name RootManageSharedAccessKey
Expected OutputExpected
{ "keyName": "RootManageSharedAccessKey", "primaryConnectionString": "Endpoint=sb://example-eh-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=", "secondaryConnectionString": "Endpoint=sb://example-eh-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY=", "rights": [ "Listen", "Send", "Manage" ] }
→
--name - Specifies the authorization rule name to get keys for
Key Concept

If you remember nothing else from this pattern, remember: Event Hubs lets you collect and process many messages in real time by creating namespaces, event hubs, and consumer groups.

Common Mistakes
Trying to send or receive data before creating a consumer group.
Without a consumer group, clients cannot read data independently, causing conflicts or failures.
Always create a consumer group for each independent reader before consuming data.
Using the wrong resource group or namespace name in CLI commands.
Commands fail because the specified resources do not exist or are not found.
Double-check resource group and namespace names exactly match what was created.
Not retrieving the connection string before trying to connect to Event Hubs.
Clients cannot authenticate or send/receive data without the connection string.
Use the authorization rule keys list command to get the connection string first.
Summary
Deploy an Event Hubs namespace and Event Hub using a Bicep template.
Verify the Event Hub creation with the Azure CLI show command.
Create consumer groups to allow multiple independent readers.
Retrieve connection strings to connect clients for sending or receiving data.

Practice

(1/5)
1. What is the main purpose of Azure Event Hubs in cloud infrastructure?
easy
A. To manage user identities and access
B. To store data permanently like a database
C. To collect and stream large amounts of data in real time from multiple sources
D. To host virtual machines for applications

Solution

  1. Step 1: Understand Event Hubs role

    Event Hubs is designed to collect and stream data from many sources in real time, acting like a big pipeline for data.
  2. Step 2: Compare other options

    Options A, B, and C describe other Azure services like identity management, databases, and virtual machines, not Event Hubs.
  3. Final Answer:

    To collect and stream large amounts of data in real time from multiple sources -> Option C
  4. Quick Check:

    Event Hubs = real-time data streaming [OK]
Hint: Event Hubs streams data live, not stores or hosts [OK]
Common Mistakes:
  • Confusing Event Hubs with databases
  • Thinking Event Hubs manages users
  • Assuming Event Hubs runs virtual machines
2. Which of the following is the correct way to create an Event Hub namespace using Azure CLI?
easy
A. az eventhubs create namespace --resource MyNamespace --group MyResourceGroup --location eastus
B. az eventhubs namespace create --name MyNamespace --resource-group MyResourceGroup --location eastus
C. az namespace eventhubs create --name MyNamespace --group MyResourceGroup --location eastus
D. az create eventhubs namespace --resource-group MyResourceGroup --name MyNamespace --region eastus

Solution

  1. Step 1: Recall Azure CLI syntax for Event Hubs namespace

    The correct command starts with az eventhubs namespace create followed by required parameters.
  2. Step 2: Check parameters and order

    az eventhubs namespace create --name MyNamespace --resource-group MyResourceGroup --location eastus uses correct parameter names: --name, --resource-group, --location. Other options have wrong command order or parameter names.
  3. Final Answer:

    az eventhubs namespace create --name MyNamespace --resource-group MyResourceGroup --location eastus -> Option B
  4. Quick Check:

    Correct CLI syntax = az eventhubs namespace create --name MyNamespace --resource-group MyResourceGroup --location eastus [OK]
Hint: Use 'az eventhubs namespace create' with proper flags [OK]
Common Mistakes:
  • Mixing command order
  • Using wrong parameter names
  • Confusing resource group and namespace names
3. Given an Event Hub with 4 partitions and a retention period of 2 days, what happens if data is sent continuously for 3 days without reading it?
medium
A. Data is duplicated across partitions to increase retention
B. All 3 days of data are stored permanently
C. Event Hub stops accepting new data after 2 days
D. Data older than 2 days is automatically removed, so only the last 2 days of data remain

Solution

  1. Step 1: Understand retention period effect

    Retention period defines how long data is kept. After 2 days, older data is deleted automatically.
  2. Step 2: Analyze continuous data sending

    Since data is sent for 3 days, data from the first day exceeds retention and is removed, leaving only last 2 days.
  3. Final Answer:

    Data older than 2 days is automatically removed, so only the last 2 days of data remain -> Option D
  4. Quick Check:

    Retention period limits data age [OK]
Hint: Retention period limits data age, older data is deleted [OK]
Common Mistakes:
  • Assuming data is stored forever
  • Thinking partitions increase retention
  • Believing Event Hub stops on retention limit
4. You have an Event Hub configured with 2 partitions but your streaming application is only reading from one partition. What issue might occur?
medium
A. Data from the unread partition will accumulate and may cause delays or data loss
B. Event Hub will automatically merge partitions to fix the issue
C. The application will read data from both partitions anyway
D. Partitions do not affect data reading, so no issue occurs

Solution

  1. Step 1: Understand partition role in Event Hubs

    Partitions split data streams. Each partition must be read to process all data.
  2. Step 2: Analyze reading from only one partition

    If only one partition is read, data in the other partition accumulates, risking delays or data loss if retention expires.
  3. Final Answer:

    Data from the unread partition will accumulate and may cause delays or data loss -> Option A
  4. Quick Check:

    Unread partitions cause data buildup [OK]
Hint: Read all partitions to avoid data backlog [OK]
Common Mistakes:
  • Assuming automatic partition merging
  • Thinking one reader covers all partitions
  • Ignoring partition impact on data flow
5. You want to design an Event Hub solution to handle a sudden spike of 10,000 events per second for 10 minutes, then normal traffic. Which approach is best to ensure no data loss and smooth processing?
hard
A. Create an Event Hub namespace with enough throughput units and increase partitions to distribute load
B. Use a single partition with default throughput units and rely on retry logic in the consumer
C. Set retention period to 1 hour to keep data longer during spikes
D. Disable partitions and use a single stream to simplify processing

Solution

  1. Step 1: Understand throughput units and partitions

    Throughput units control capacity. More partitions allow parallel processing and better load distribution.
  2. Step 2: Analyze spike handling

    To handle 10,000 events/sec, increase throughput units and partitions to avoid throttling and data loss during spikes.
  3. Step 3: Evaluate other options

    Use a single partition with default throughput units and rely on retry logic in the consumer risks overload; C affects retention but not throughput; D disables partitions which reduces scalability.
  4. Final Answer:

    Create an Event Hub namespace with enough throughput units and increase partitions to distribute load -> Option A
  5. Quick Check:

    Scale throughput and partitions for spikes [OK]
Hint: Scale throughput units and partitions for high load [OK]
Common Mistakes:
  • Relying on single partition for high load
  • Confusing retention with throughput
  • Disabling partitions reduces scalability