Skip to content

Instantly share code, notes, and snippets.

@kavimaluskam
Last active January 30, 2019 09:49
Show Gist options
  • Save kavimaluskam/6767930c25274a81cf07260f019c6b6c to your computer and use it in GitHub Desktop.
Save kavimaluskam/6767930c25274a81cf07260f019c6b6c to your computer and use it in GitHub Desktop.
Cheat sheet for Kafka Topic CRUD
# Enter Kafka Shell Client
make kafka-shell
# Assign testing topic name in variable
TOPIC=test
# Describe all topic
kafka-topics --describe --zookeeper $ZK
# Create topic
kafka-topics --create --topic $TOPIC --partitions 4 --zookeeper $ZK --replication-factor 2
# Describe partitions, replication, leader brokers for selected topic
kafka-topics --describe --zookeeper $ZK --topic $TOPIC
# Count the number of messages inside a topic
kafka-run-class kafka.tools.GetOffsetShell --broker-list=$BROKERS --topic $TOPIC --time -1
# Update retention policy of a topic
# "-1" means forever
kafka-configs --zookeeper $ZK --alter --entity-type topics --entity-name $TOPIC --add-config retention.ms=-1
kafka-configs --zookeeper $ZK --alter --entity-type topics --entity-name $TOPIC --add-config retention.bytes=-1
# Delete topics
kafka-topics --delete --topic $TOPIC --zookeeper $ZK
# Exit Docker when CRUD is done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment