☰ 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
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.
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:
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:
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
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
Start the Kafka broker service: Execute the following command from inside the Kafka root folder.
.\bin\windows\kafka-server-start.bat .\config\server.properties
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
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
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:
All Chapters