Apache Kafka provides a powerful set of command-line tools to help developers and administrators manage their Kafka clusters, topics, producers, and consumers.
Whether you’re getting started or managing production workloads, these CLI commands are essential for working with Kafka in a ZooKeeper-based setup.
Below are the most commonly used Kafka CLI commands to help you start servers, create topics, send and consume messages, and manage configurations effectively.
1. Start ZooKeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
2. Start Kafka Broker (Server)
bin/kafka-server-start.sh config/server.properties
3. Create a Topic
bin/kafka-topics.sh \ --create \ --topic my-topic \ --bootstrap-server localhost:9092 \ --partitions 3 \ --replication-factor 1
4. List All Topics
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
5. Describe a Topic
bin/kafka-topics.sh \ --describe \ --topic my-topic \ --bootstrap-server localhost:9092
6. Send Messages Using Producer
bin/kafka-console-producer.sh \ --topic my-topic \ --bootstrap-server localhost:9092
7. Consume Messages from a Topic
bin/kafka-console-consumer.sh \ --topic my-topic \ --bootstrap-server localhost:9092 \ --from-beginning
8. Change Topic Configuration (e.g., Retention Time)
bin/kafka-configs.sh \ --alter \ --bootstrap-server localhost:9092 \ --entity-type topics \ --entity-name my-topic \ --add-config retention.ms=172800000
9. View Topic Configurations
bin/kafka-configs.sh \ --describe \ --bootstrap-server localhost:9092 \ --entity-type topics \ --entity-name my-topic
10. Increase Partitions in a Topic
bin/kafka-topics.sh \ --alter \ --topic my-topic \ --partitions 6 \ --bootstrap-server localhost:9092