Close

Installing and Running Kafka

[Last Updated: Mar 16, 2020]

Kafka 

In this tutorial we are going to install and run Kafka (2.4.1) on windows

Download Kafka

Download Kafka here. In this tutorial, we downloaded kafka_2.12-2.4.1.tgz

Extract tgz via git-bash to a location of your choice:

$ tar -xvzf kafka_2.12-2.4.1.tgz

Running ZooKeeper Server

Kafka uses ZooKeeper.

Let's run ZooKeeper with following command:

D:\kafka_2.12-2.4.1>bin\windows\zookeeper-server-start.bat config/zookeeper.properties

Running Kafka Server

In new cmd window:

D:\kafka_2.12-2.4.1>bin\windows\kafka-server-start.bat config/server.properties

Creating a Topic

Open a new cmd window:

D:\kafka_2.12-2.4.1>bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic my-test-topic

Listing existing topics

D:\kafka_2.12-2.4.1>bin\windows\kafka-topics.bat --list --bootstrap-server localhost:9092
__consumer_offsets
my-test-topic

Sending messages to a topic from command line

D:\kafka_2.12-2.4.1>bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic my-test-topic
>one
>two
>

Starting command line Consumer

Open a new cmd window:

D:\kafka_2.12-2.4.1>bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic my-test-topic --from-beginning
one
two

Also see how to use Producer and Consumer API in Java here.

See Also