Skip to content

Instantly share code, notes, and snippets.

@sankars
Created April 2, 2018 09:39
Show Gist options
  • Save sankars/09ea22b28b55a2b3676cf7d84aa4075e to your computer and use it in GitHub Desktop.
Save sankars/09ea22b28b55a2b3676cf7d84aa4075e to your computer and use it in GitHub Desktop.
Kafka Commands
############################ Topic related commands
## create a topic
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
## topic info
kafka-topics.sh --zookeeper localhost:2181 --describe --topic test
## increase partitions
kafka-topics.sh --zookeeper localhost:2181 --alter --topic test --partitions 16
## delete topic
kafka-topics.sh --zookeeper localhost:2181 --delete --topic test
## list topics
kafka-topics.sh --zookeeper localhost:2181 --list
## list of under replicated partitions
kafka-topics.sh --zookeeper localhost:2181 --describe --under-replicated
############################ Consumer Group related commands
## list old consumer groups. uses ZK
kafka-consumer-groups.sh --zookeeper localhost:2181 --list
## list new consumer-groups. uses kafka
kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9092/kafka-cluster --list
## consumer group info
kafka-consumer-groups.sh --zookeeper localhost:2181 --describe --group testgroup
## delete consumer group. supported only in old
kafka-consumer-groups.sh --zookeeper localhost:2181 --delete --group testgroup
## delete offset for a consumer group listening for a topic. supported only in old
kafka-consumer-groups.sh --zookeeper localhost:2181 --delete --group testgroup --topic my-topic
############################
kafka-console-producer.sh --broker-list localhost:9092 --topic test
kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
############################
kafka-run-class.sh kafka.tools.DumpLogSegments
## export offsets for a consumer group
kafka-run-class.sh kafka.tools.ExportZkOffsets --zkconnect localhost:2181 --group testgroup --output-file offsets
kafka-run-class.sh kafka.tools.ImportZkOffsets --zkconnect localhost:2181 --input-file offsets
############################
## change config for a topic
kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name test --add-config <KEY<=<VALUE>,[<KEY<=<VALUE
## describle overrided config
kafka-configs.sh --zookeeper localhost:2181 --describe --entity-type topics --entity-name my-topic
## remove a overrided config
kafka-configs.sh --zookeeper zoo1.example.com:2181/kafka-cluster --alter --entity-type topics --entity-name my-topic --delete-config <KEY>
## change config for a client
kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type clients --entity-name client1 --add-config <KEY<=<VALUE>,[<KEY<=<VALUE>]
##############################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment