in DevOps

Some Kafka Command line Examples

You may download latest kafka source from https://kafka.apache.org/downloads .

Kafka command-line tools are located in bin/ of source directory.

  • kafka-topics.sh

Create, alter, list, and describe topics. For example.

# List topics
$ ./bin/kafka-topics.sh --zookeeper zk.example.com:2181 --list
test-topic
test

# Create a new topics
$ ./bin/kafka-topics.sh --create --zookeeper zk.example.com:2181 --replication-factor 2 
  --partitions 1 --topic topicname 

# Describe a topic
$ ./bin/kafka-topics.sh --zookeeper zk.example.com:2181 --describe --topic topicname

 

  • kafka-console-consumer.sh

Read data from a Kafka topic and write it to standard output. For example.

$ ./bin/kafka-console-consumer.sh --zookeeper zk.example.com:2181 --topic test-topic

Note: To consumes events from beginning can append --from-beginning .

 

  • kafka-console-producer.sh

Read data from standard output and write it to a Kafka topic. For example.

$ ./bin/kafka-console-producer.sh --broker-list kafka.example.com:9092,kafka03.example.com:9092 --topic test-topic