Apache Kafka on Windows
Editor’s note: The post was origially published in December 2013 and has been updated to reflect the changes to Apache Kafka from 0.8.0 to 3.4.0
Introduction
Kafka is a distributed messaging system developed by LinkedIn and later donated to Apache as an open source project. The main purpose of creating Kafka was collecting and delivering high volume of log data with low latency.
Below are the steps we will follow for Windows operating system.
- Download Apache Kafka version 3.4.0 from here
- Install Java 8 in your Windows OS
- Configure Zookeeper and Kafka bootstrap server
- Verify the producer and consumer communication
Configure Apache Kafka environment
- Unzip the Kafka distribution to a folder of your choice e.g.
C:\git\kafka_2.12-3.4.0
. All commands will be executed from the root folder of Apache Kafka distribution - Ensure you have the Java environment configured using
java -version
. Below is the expected output.C:\git\kafka_2.12-3.4.0> java -version openjdk version "1.8.0_362" OpenJDK Runtime Environment Corretto-8.362.08.1 (build 1.8.0_362-b08) OpenJDK 64-Bit Server VM Corretto-8.362.08.1 (build 25.362-b08, mixed mode)
- Open the command line terminal and start the Zookeeper instance
C:\git\kafka_2.12-3.4.0> bin\windows\zookeeper-server-start.bat config\zookeeper.properties
- Open the another command line terminal and start the Zookeeper instance
C:\git\kafka_2.12-3.4.0> bin\windows\kafka-server-start.bat config\server.properties
Verify the installation
- Creating a topic
C:\git\kafka_2.12-3.4.0> bin\windows\kafka-topics.bat --create --topic demo-events --bootstrap-server localhost:9092 Created topic demo-events
- Sending a message via producer
C:\git\kafka_2.12-3.4.0> bin\windows\kafka-console-producer.bat --topic demo-events --sync --bootstrap-server localhost:9092
- Receiving a message via consumer
C:\git\kafka_2.12-3.4.0> bin\windows\kafka-console-consumer.bat --topic demo-events --bootstrap-server localhost:9092 --from-beginning
- Any messages typed out in the producer terminal will be replicated by the brokers and displayed in the consumer terminal
- Kafka logs are stored in
C:\tmp\kafka-logs
and Zookeeper logs are stored inC:\tmp\zookeeper