How to install Kafka on Windows machine
How to install Kafka on Windows machine
Preface
Kafka is an open-source tool used for building real-time data processing pipelines.
In this cpurse, I will show you how to download and set up Kafka on your Windows machine.
Steps
1. Install Java & JDK
2. Set up environment variables
3. Install Kafka
4. Set up configuration files
5. Test Kafka
A. Java
Enter “download Java” in your browser
Click on the first link from the official website
Click on Download Java then click on the downloaded file
Follow instructions from the Java installation wizard
Once it looks like the above, click all the OK buttons until you exit the environment
variables page
Enter the command (cmd) prompt and type java -version. You should get the latest
version of java displayed like so:
3. Install Kafka
Enter “download Kafka” into your browser
Click on the first link from the official website. You should see the website is sorted
by versions (the latest on top, earlier releases towards the bottom)
Under the latest version, click on the .tgz file next to Scala 2.13 under Binary
downloads, which should download the latest Kafka version as a compressed file.
Unzip the .tgz file to get a folder named kafka_2.13-3.4.0.
Unzip the tar file in this folder too. Once you have this folder, copy and paste it to the
root of your C drive
B. Zookeeper file
Return to the config folder and open the zookeeper.properties file in a notepad
In the file replace “dataDir=/tmp/zookeeper” with
“dataDir=C:/kafka/kafka_logs/zookeeper_logs”
Save and exit the file.
5. Test Kafka
Let’s confirm the installation and configurations worked by starting the Zookeeper and Kafka
servers.
C:\\kafka\\bin\\windows\\zookeeper-server-start.bat C:\\kafka\\config\\
zookeeper.properties
C:\\kafka\\bin\\windows\\kafka-server-start.bat C:\\kafka\\config\\
server.properties
Once the servers are running, we can test if Kafka works by:
1. Creating a topic
2. Creating a producer
3. Creating a consumer
We’ll create a producer to send messages to the consumer. The consumer will subscribe to a
topic we’ll name demo_topic, and the consumer will display the messages from the topic to
the terminal as a validation check that the installation and configuration were successful.
In the commands below, we’ll replace <host>:<port> for localhost:9092 and <topic-name>
for demo_topic.
1. Create a topic
The replications factor specifies the number of copies of each message which will be stored
across multiple broker instances. If the main broker crashes or fails to send a message for any
reason, another broker can step in to ensure the message is delivered to the appropriate topic
without interruption. This is one of the features of Kafka that make it a fault-tolerance
streaming tool.
The partitions are the number of chunks the messages are split into. Each topic can have
multiple partitions, and each partition can be stored on different brokers, which adds to the
scalability of the event processor.
2. Create a producer
C:\\kafka\\bin\\windows\\kafka-console-producer.bat --broker-list
127.0.0.1:9092 --topic <topic-name>
3. Create a consumer
This will return all messages from the start of the topic’s inception. You can consume only
new messages from the topic by removing the --from-beginning flag.
Here is what the producer (left) and consumer (right) look like from a terminal perspective:
Note: the terminals can be opened in an IDE like VS Code too, which makes it easier to
manage multiple terminals in one session.
Congrats! You have successfully installed and configured Kafka on your machine🎉!
Delete a topic
If you want to delete a Kafka topic, you can also run this command:
Replace the <host>:<port> with localhost:9092 and <topic_name> with demo_topic once
you’re done. Once you’re comfortable with the whole process, you can configure the host,
port, topic name and other variables to your preferences.