Installing and running KAFKA on windows

May 22, 2019

Softwares and packages to be installed:

Download and install Java if not installed already, and then download other packages related to KAFKA. May be you can create a dir called kafka and keep all the packages and tools.

I have downloaded the following files

Use WinRAR or any other tool to untar the downloaded zookeeper and kafka tar files.

Now my directory structure will be

  • C:/kafka/kafka_2.12-1.0.1
  • C:/kafka/zookeeper-3.4.10

Installing Zookeeper

Setting up Zookeeper

  • Get in to conf directory of zookeeper
    • C:/kafka/zookeeper-3.4.10/conf
  • Find zoo_sample.cfg and rename to zoo.cfg
  • Search for dataDir setting in zoo.cfg and update as follows
    • dataDir=C:/kafka/zookeeper-3.4.10/data
  • In case, if you want to change the port no from default (2181), change it in zoo.cfg
  • Add system env variable for zookeeper
    • ZOOKEEPER_HOME = C:\kafka\zookeeper-3.4.10
  • Add zookeeper bin directory to Path env variable
    • %ZOOKEEPER_HOME%\bin
  • Now all set for running the zookeeper server

Running Zookeeper

  • Open Command Prompt
  • Type zkserver, and enter

kafka 1

Don’t close and leave the terminal as it is

Installing Kafka

Setting up KAFKA

  • Get in to the Kafka config directory
    • C:\kafka\kafka_2.12-1.0.1\config
  • Find the file called server.properties
  • Update log.dirs
    • log.dirs=C:/kafka/kafka_2.12-1.0.1/kafka-logs
  • In case if you made any changes in Zookeeper config (host and port), then update the same here as well
  • Now all set for running your Kafka

Running Kafka

  • Get in to the kafka directory
    • C:\kafka\kafka_2.12-1.0.1
  • Run the following command
    • .\bin\windows\kafka-server-start.bat  .\config\server.properties

kafka 2

Kafka Topic

Creating a topic

cd C:\kafka\kafka_2.12-1.0.1\bin\windows kafka-topics.bat —create —zookeeper localhost:2181 —replication-factor 1 —partitions 1 —topic test.topic

kafka 3

Produce message in a topic

cd C:\kafka\kafka_2.12-1.0.1\bin\windows kafka-console-producer.bat —broker-list localhost:9092 —topic test.topic

kafka 4

Consume messages from a topic

cd C:\kafka\kafka_2.12-1.0.1\bin\windows kafka-console-consumer.bat —bootstrap-server localhost:9092 —topic test.topic —from-beginning

kafka 5

List all topics

cd C:\kafka\kafka_2.12-1.0.1\bin\windows kafka-topics.bat —list —zookeeper localhost:2181

Deleting a topic

cd C:\kafka\kafka_2.12-1.0.1\bin\windows kafka-topics.bat —delete —zookeeper localhost:2181 —topic test.topic