kafka-console-consumer CLI.
What you’ll learn:
- How to create multiple consumers in the same group
- How partitions are distributed among consumers
- What happens when consumers join or leave a group
- How offsets are committed and resumed
--group flag.
How to create consumers in a Kafka consumer group?
To start consumers in a consumer group, do the following:- Create a topic with at least 2 partitions and send data to it
- Create a first
kafka-console-consumerand assign a group name with--group - Open a new terminal / shell window
- Create a second
kafka-console-consumerand use the same--groupargument - Send data to the topic and you will see consumers sharing the reads
Create consumer group example
You cannot have more consumers in a group than partitions in your Kafka topic, and therefore we first need to create a Kafka topic with a few partitions (in the example 3).my-first-application
my-first-application (note we’re using the exact same command)
my-first-application
my-first-application will get assigned a partition. Produce a few string messages in the topic.
Stop all consumers
And keep on producing to the topicGotchas
-
If you consume in a consumer groups using the
--groupcommand, then if you try using the--from-beginningoption afterwards with the same group, it will be ignored. Instead, you need to reset your consumer groups as shown here. - If you don’t specify a —group option, the consumer group of the consumer will be a random consumer group such as console-consumer-11984
-
If you see one consumer getting all the messages, that probably means that your topic was only created with 1 partition, which you can verify with the
kafka-topics --describecommand
Consumer group behavior summary
| Scenario | Result |
|---|---|
| 3 consumers, 3 partitions | Each consumer gets 1 partition |
| 2 consumers, 3 partitions | One consumer gets 2 partitions |
| 4 consumers, 3 partitions | One consumer sits idle |
| Consumer leaves group | Partitions rebalanced to remaining consumers |
| Consumer joins group | Rebalance distributes partitions |
See it in practice with ConduktorConduktor Console displays consumer group membership, partition assignments, and lag metrics in real-time. Monitor rebalances and track consumer health visually.
Next steps
- Manage consumer group offsets with kafka-consumer-groups
- Understand incremental rebalancing for production
- Configure consumer settings for stability