Apache Kafka Guide #27 Consumer Groups CLI & Resetting Offset
Hi, this is Paul, and welcome to the #27 part of my Apache Kafka guide. Today we will discuss how to use Apache Kafka Consumer Groups CLI.
List all Consumer Groups
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --list
And we have all consumer groups including temporary ones. Temporary it’s the groups created automatically when you run consumer without specifying the group will be named like console-consumer-48392
and it will be deleted automatically in some amount of time, you do need to carry about it.
Describe Consumer Group
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group group-name
Delete Consumer Group and Resetting Offsets
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --delete --group group-name
It’s possible for groups without active Consumers this delete all information about Consumer Group inclusive offsets.
Resetting Offsets
It is possible to reset the application’s offsets to the very start to reprocess all messages. This capability is provided by Kafka consumer groups through a feature known as “reset offsets”. By using the command --reset-offsets
, we can adjust the offsets to-earliest
, targeting the initial data available within the topic. To preview the outcome of this adjustment without making actual changes, we employ the --dry-run
option, which reveals the intended assignment.
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group group-name --reset-offsets --to-earliest --topic topic-name --dry-run
--dry-run
— used for testing purposes just watch what happen
Instead of using the --dry-run
option, for real execution we use -- execute
. This action effectively resets the offsets. Currently, if we apply the --execute
command, the new offsets will be set to 0.
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group group-name --reset-offsets --to-earliest --topic topic-name --execute
Reminder you always can see all the features in the documentation, just:
$ kafka-consumer-groups
to the console.
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us on Twitter(X), LinkedIn