-
Notifications
You must be signed in to change notification settings - Fork 2
EventHubs
The Event Hub toolset is designed to simplify interaction with Azure Event Hubs for testing, debugging, and monitoring event-driven systems. It provides two primary functionalities:
- Event Producer: A tool that enables users to send events to an Azure Event Hub for testing purposes.
- Event Consumer: A tool for consuming and monitoring events from an Event Hub.
These tools facilitate testing, monitoring, and debugging event-driven systems using Azure Event Hubs.
First, we need to create an Event Hub Namespace, which is a logical container for one or more Event Hubs. Follow these steps to configure an Event Hub for testing purposes:
- Open the Azure Portal and search for Event Hubs.
- Create a new Event Hub Namespace:
- Choose a unique namespace name.
- Select the Basic pricing tier for cost-efficient testing.
- Set Throughput Units to 1.
- Finalize the setup by clicking Create.
- Navigate to your newly created Event Hub Namespace.
Having an Event Hub Namespace alone will not be sufficient. We need to create one or more Event Hubs within this namespace.
- Within the Event Hub Namespace, click + Event Hub to create a new Event Hub.
-
Name: For example,
MyFirstEventHub
- Partition count: Set to 2 for balanced workload distribution.
-
Cleanup policy: Choose
Delete
and set the Retention period to 1 hour to avoid long-term data storage. - Capture: Disable capture if not needed.
-
Name: For example,
- Click Create to create the Event Hub.
Next, we must locate the connection string for the newly created Event Hub:
- In the Event Hub you've just created, navigate to Settings -> Shared access policies.
- If no policies are available, create a new one:
- Click Add.
- Provide a name (e.g.,
EventHubPolicy
). - Select permissions for Send and Listen.
- After creating the policy, click on it to view and copy the connection string.
- Click on the policy and copy one of the connection strings.
- Make sure to copy the connection string from the Event Hub level, not the namespace level.
- The Send and Listen permissions are essential for the Event Sender and Event Consumer tools to interact with the Event Hub.
The Event Sender tool provides an intuitive interface to send test events to an Event Hub. Follow these steps:
- Navigate to the Event Hub -> Send Events to Event Hub page.
- Enter the connection string retrieved from the Event Hub in the previous step.
- Input the start number for the events. This number helps track the event series.
- Specify the number of events to be sent.
- Click the Send Events button.
The tool alternates between sending two types of events: EventHubOrderEvent and EventHubProductEvent. These events are sent with a partition key, either "order"
or "product"
, ensuring balanced distribution across two partitions.
-
EventHubOrderEvent: Represents an order-related event.
- Example:
{ "OrderId": 1002, "CustomerName": "Customer 1002" }
- Partition key:
"order"
- Example:
-
EventHubProductEvent: Represents a product-related event.
- Example:
{ "ProductId": 1003, "ProductName": "Product 1003" }
- Partition key:
"product"
- Example:
These events are serialized as JSON and sent to the Event Hub with different partition keys to simulate diverse event traffic in a production scenario. Events with even numbers are sent as EventHubOrderEvent
, while events with odd numbers are sent as EventHubProductEvent
.
The Event Consumer tool allows you to monitor and consume events from an Azure Event Hub, making it easy to debug and analyze the events flowing through your system. The tool reads events from two partitions and displays event details, allowing you to see the exact event data along with its metadata.
Follow these steps to consume events from an Event Hub:
- Navigate to the Event Hub -> Consume Events From Event Hub page.
- Enter the connection string from the Event Hub, which you can retrieve through the Azure Portal (as shown in the setup steps).
- Specify the consumer group. By default, this will be set to
"$Default"
, which is the Event Hub's default consumer group. - Click the Consume Events button.
Once you submit the form, the tool connects to the Event Hub using the provided connection string and consumer group and begins consuming events. The tool will display the following event details:
- ContentType: The type of content within the event.
- CorrelationId: A unique identifier used for tracking the flow of events across systems.
- EnqueuedTime: The time the event was enqueued in the Event Hub (in ISO 8601 format).
- MessageId: A unique identifier for the message.
- PartitionKey: The key that determines the partition where the event is stored.
- SequenceNumber: The unique number identifying the event sequence within the partition.
- Offset: The position of the event in the partition.
Events from different partitions are displayed in separate columns for easy comparison. Each event's body and metadata are presented for a detailed view of what was processed.
Here is a sample output of the Event Consumer tool:
Offset: 12345
PartitionId: 0
Event Details:
ContentType: application/json
CorrelationId: abc123
EnqueuedTime: 2024-10-10T14:35:22.000Z
MessageId: msg-1001
PartitionKey: order
SequenceNumber: 1001
Body: {"OrderId": 1001, "CustomerName": "Customer 1001"}
#### Partition 1:
Offset: 67890
PartitionId: 1
Event Details:
ContentType: application/json
CorrelationId: def456
EnqueuedTime: 2024-10-10T14:35:24.000Z
MessageId: msg-1002
PartitionKey: product
SequenceNumber: 1002
Body: {"ProductId": 1002, "ProductName": "Product 1002"}
This sample output shows events consumed from two partitions (Partition 0 and Partition 1), with each partition displaying its respective events and metadata. This tool shows the two first partitions.