×
☰ See All Chapters

How to Install and setup Apache Kafka on Windows

Step1: Download and Install Kafka Binary

Download Apache Kafka binary from official site https://kafka.apache.org/downloads

how-to-install-kafka-0
 

Navigate to the folder where kafka binary is downloaded, extract the files and move the extracted folder to the directory where you wish to keep the files. In our example we have extracted to H:\JDE\Kafka\kafka_2.12-3.5.1 folder. From now on we refer this folder as kafka root folder. You may have to extract twice, first to extract tar file from tgz and then to extract files from tar file.

how-to-install-kafka-1
 

 Step 2: Setup zookeeper.properties file

Go inside kafka config folder (H:\JDE\Kafka\kafka_2.12-3.5.1\config\) and open zookeeper.properties file. Configure dataDir to H:/JDE/Kafka/zookeeper as shown below:

how-to-install-kafka-2
 

Step 3: Setup kafka server.properties

Go inside kafka config folder (H:\JDE\Kafka\kafka_2.12-3.5.1\config\) and open server.properties and scroll down Configure og.dirs to H:/JDE/Kafka/ kafka-logs as shown below:

how-to-install-kafka-3
 

In some systems you may see the error kafka broker not available at starting, in that case uncomment the following line from server.properties file:

#listeners=PLAINTEXT://:9092

 

Change this line to

listeners=PLAINTEXT://127.0.0.1:9092

how-to-install-kafka-4
 

Step 4: Start the Kafka Environment

Start the ZooKeeper service: Execute the following command from inside the Kafka root folder.

.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties

how-to-install-kafka-5
 

Start the Kafka broker service: Execute the following command from inside the Kafka root folder.

.\bin\windows\kafka-server-start.bat .\config\server.properties

how-to-install-kafka-6
 

Step 5: Create Topic to store events

Execute the following command from inside the Kafka root folder.

.\bin\windows\kafka-topics.bat --create --topic demotopic --bootstrap-server localhost:9092

how-to-install-kafka-7
 

Step 6: Test the installation

Write events to topic: Execute the following command from inside the Kafka root folder.

.\bin\windows\kafka-console-producer.bat --topic demotopic --bootstrap-server localhost:9092

As soon as the above command executed, console will allow ypu to enter the event messages, we have passed 4 messages, test, hello, Manu, HelloWorld
how-to-install-kafka-8
 

Read events from topic: Execute the following command from inside the Kafka root folder.

.\bin\windows\kafka-console-consumer.bat --topic demotopic --from-beginning --bootstrap-server localhost:9092

This command will read all published messages from beginning and prints all messages on console as shown below:

how-to-install-kafka-9
 

All Chapters
Author