Event Hubs Consumer Groups

In Azure Event Hubs, a consumer group is a named logical view of the event stream. Each consumer group allows a separate application, or a distinct component within an application, to independently consume from the event stream. This is crucial for scenarios where multiple applications need to process the same data without interfering with each other.

Why Use Consumer Groups?

When you create an Event Hub, it comes with a default consumer group named $Default. However, you'll typically need to create additional consumer groups to:

Key Concepts of Consumer Groups

1. Naming Conventions

Consumer group names can be up to 64 characters long and must be unique within an Event Hub. They can contain alphanumeric characters and hyphens. The special name $Default is reserved for the default consumer group.

2. Offsets and Event Sequencing

Each consumer group maintains its own position (offset) in the event stream for each partition. This offset indicates the next event to be read by a consumer in that group. When a consumer reads an event, its offset advances. If a consumer restarts, it will resume reading from its last recorded offset within its specific consumer group.

3. Consumer Group Creation

You can create consumer groups using:

4. Default Consumer Group ($Default)

The $Default consumer group is automatically created when an Event Hub is created. It's often used for simple scenarios or as a fallback. However, for production workloads, it's best practice to create dedicated consumer groups for your applications.

5. Multiple Consumer Groups

An Event Hub can have a large number of consumer groups (up to 20,000 by default, but this limit can be increased). This allows for extensive customization of data consumption patterns.

Example Scenario

Imagine an IoT solution sending sensor data to an Event Hub.

Each of these consumer groups will independently track its position in the event stream, ensuring that data is processed correctly by each component.

Best Practices

Note: Consumer group names are case-insensitive but are stored and returned in their original casing.

Related Topics