Kafka CLI Quick Reference
Create topics, produce and consume messages, and inspect consumer-group lag from the command line.
Topics
- Create
kafka-topics.sh --create --topic orders --partitions 6 --replication-factor 3 --bootstrap-server localhost:9092- List / describe
kafka-topics.sh --list …·--describe --topic orders …- Add partitions
kafka-topics.sh --alter --topic orders --partitions 12 …(can’t shrink)- Delete
kafka-topics.sh --delete --topic orders …
Produce & consume
- Produce (stdin)
kafka-console-producer.sh --topic orders --bootstrap-server …- Produce with key
- add
--property parse.key=true --property key.separator=: - Consume from start
kafka-console-consumer.sh --topic orders --from-beginning …- Consume in a group
- add
--group my-group— offsets are committed - Show keys
- add
--property print.key=true
Consumer groups (lag)
- List groups
kafka-consumer-groups.sh --list --bootstrap-server …- Describe (lag!)
kafka-consumer-groups.sh --describe --group my-group …— CURRENT-OFFSET, LOG-END-OFFSET, LAG- Reset offsets
--reset-offsets --to-earliest --topic orders --execute --group my-group