Most Useful Kafka CLI Commands
kafka-topics --zookeeper localhost:2181 --topic topic_name --create --partitions #_of_partitions --replication-factor #_of_replication_factor
Example:
kafka-topics --zookeeper localhost:2181 --topic gocode --create --partitions 3 --replication-factor 1
2. List all topics
kafka-topics --zookeeper localhost:2181 --list
3. Describe topic
kafka-topics --zookeeper localhost:2181 --topic topic_name --describe
4. Delete topic
kafka-topics --zookeeper localhost:2181 --topic topic_name --delete
5. To create a producer
kafka-console-producer --broker-list localhost:9092 --topic topic_name
6. Set property for producer
kafka-console-producer --broker-list localhost:9092 --topic topic_name --producer-property acks=all
7. To create consumer
kafka-console-consumer --bootstrap-server localhost:9092 --topic topic_name
8. To create a consumer that read from the beginning for a topic
kafka-console-consumer --bootstrap-server localhost:9092 --topic topic_name --from-beginning
Note: # is a short form of "number"
Leave a Comment