Namespaces and Event Hubs
Azure Event Hubs is a highly scalable data streaming platform and event ingestion service. It provides a message broker that can ingest millions of events per second. Understanding the core components, namely Namespaces and Event Hubs, is fundamental to effectively using Event Hubs.
Namespaces
An Event Hubs namespace is a logical container for Event Hubs instances. It provides a unique scope and a FQDN (fully qualified domain name) for your Event Hubs resources. Think of it as a top-level organizational unit for your event-driven applications.
- Unique Scope: All Event Hubs, consumer groups, and authorization rules are created within a namespace.
- FQDN: Each namespace gets a unique FQDN, which is used in connection strings to access the resources within it. For example:
your-namespace.servicebus.windows.net. - Region: A namespace is associated with a specific Azure region.
- Pricing Tier: The pricing tier (Basic, Standard, Premium) is defined at the namespace level, affecting features and throughput.
Event Hubs
An Event Hub is the actual entity within a namespace that stores events. It's the core component where event data is published and consumed.
- Data Storage: Events are published to an Event Hub.
- Partitions: An Event Hub is divided into one or more partitions. Partitions are ordered, immutable sequences of events. This partitioning is key to Event Hubs' scalability and parallel processing capabilities.
- Retention Period: Events are retained in an Event Hub for a configurable period (e.g., 24 hours, 7 days), after which they are automatically deleted.
- Throughput Units (TUs): The capacity and performance of an Event Hub are managed through Throughput Units (configured at the namespace level, but influencing the Event Hub's capacity).
Relationship: Namespace to Event Hub
A namespace acts as a container for one or more Event Hubs. You can have multiple Event Hubs within a single namespace, allowing you to logically group related event streams for different applications or data sources. For instance, you might have a namespace for "IoT Data" and within that namespace, individual Event Hubs for "Temperature Sensors", "Humidity Sensors", and "Motion Detectors".
Important: Event Hubs are designed for high-throughput, low-latency data ingestion. Events are typically appended to partitions, and data is not generally queried directly from an Event Hub. Instead, consumers read streams of events.
Creating a Namespace and Event Hub
You can create Event Hubs namespaces and Event Hubs using the Azure portal, Azure CLI, PowerShell, or SDKs. Here's a conceptual example using Azure CLI:
# Create a namespace
az eventhubs namespace create \
--resource-group MyResourceGroup \
--name myEventHubsNamespace \
--location westus \
--sku Standard
# Create an Event Hub within the namespace
az eventhubs eventhub create \
--resource-group MyResourceGroup \
--namespace-name myEventHubsNamespace \
--name myEventHub \
--message-retention 7 \
--partition-count 2
Key Considerations:
- Naming Conventions: Choose clear and descriptive names for your namespaces and Event Hubs.
- Partition Count: The number of partitions in an Event Hub affects the maximum throughput and the degree of parallelism for consumers. Choose this based on your expected load and processing requirements.
- Retention Period: Configure the retention period to balance storage costs with your data availability needs.
- Pricing Tier: Select the appropriate pricing tier based on your throughput and feature requirements.
Tip: For optimal performance and scalability, plan your partitioning strategy carefully. The number of partitions should ideally be a multiple of the number of consumer instances you plan to run in parallel.