Friday 27 November 2015

How to configure and access Kafka via command line

Configuring Kafka with windows:

The commands for configuring kafka are same for both windows and linux, replace .bat with .sh for accessing in linux environment.

Step 1:
Download Apache Kafka binaries and unzip it under say D:/kafka<version>

Step 2:

Go to command prompt and run the kafka commands from windows folder under kafka<version>:

cd kafka<version>/bin/windows

Run Zookeper server:

zookeeper-server-start.bat ../../config/zookeeper.properties

Run Kafka server:

kafka-server-start.bat ../../config/server.properties

Accessing Kafka via command line utilities:

The commands for accessing kafka are same for both windows and linux, replace .bat with .sh for accessing in linux environment.

Create a topic:

kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

List the topics created:

kafka-topics.bat --list --zookeeper localhost:2181

Send some message via producer program:

kafka-console-producer.bat --broker-list localhost:9092 --topic test

start a consumer program in a different cmd to see the messages sent from producer:

kafka-console-consumer.bat --zookeeper localhost:2181 --topic test --from-beginning

For newer versions of kafka, below command needs to be used by default for console-consumer program:

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning


To publish/subscribe Kafka messages via Java API, please referUsing Java API for publish/consume Kafka messages