Skip to content

Instantly share code, notes, and snippets.

@ram-pi
Forked from filipefigcorreia/kafka-cheat-sheet.md
Created November 5, 2022 10:59
Show Gist options
  • Save ram-pi/8ce149565c395ecc4ec9384ce69ff96f to your computer and use it in GitHub Desktop.
Save ram-pi/8ce149565c395ecc4ec9384ce69ff96f to your computer and use it in GitHub Desktop.
Apache Kafka Cheat Sheet

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --delete-config retention.ms

Delete a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic mytopic

Get the earliest offset of a topic

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic mytopic --time -2

Get the latest offset of a topic

bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic mytopic --time -1

List the consumer groups known to Kafka

bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --list (old api)

bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092 --list (new api)

View the details of a consumer group

bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --group <group name> --describe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment