Hi and welcome to for-devs.com.
In this tutorial we run Apache Kafka on a Windows PC following this step by step guide. The link to this guide appears in the YouTube video description.
Step 1: Install Prerequire Software
- JKD 8 or higher
- Extracting Tool: 7-Zip
- Text editor: Notepad ++
Step 2: Download Apache Kafka
Go to the Apache Kafka download page.
For this tutorial we download kafka_2.13-3.6.1.tgz
Step 3: Extract Kafka Package
Extract the kafka_2.13-3.6.1.tgz with 7-Zip at your prefer directory.
For this guide we extract at the C:\ drive.
Kafka Configuration Folder Details
The Kafka configuration folder (in our case, C:\kafka_2.13-3.6.1\config) holds all the property files that control how Kafka works.
Kafka configuration files are utilized by Windows or Linux programs for running and managing Kafka in their environment.
Step 4: Modifying server and zookeeper Properties
- Open File Explorer, navigate to the Kafka “config” folder at C:\kafka_2.13-3.6.1\config.
- Open server.properties and insert
listeners=PLAINTEXT://127.0.0.1:9092
in line 39 . - On server.properties change line 62 to
log.dirs=C:\kafka_2.13-3.6.1\logs
, then save and close. - Open zookeeper.properties and modify line 16 to
dataDir=C:/kafka_2.13-3.6.1
then save and close.
Kafka Windows Scripts Folder
The Kafka windows folder (C:\kafka_2.13-3.6.1\bin\windows) contains all the bat scripts for running Apache Kafka on Windows:
Step 6: Start zookeeper
- Open a PowerShell or Command Prompt.
- Change to the Kafka Windows folder:
cd C:\kafka_2.13-3.6.1\bin\windows
- Start Zookeeper from the Windows folder:
.\zookeeper-server-start.bat ../../config/zookeeper.properties
This command uses windows bat file zookeeper-server-start.bat with zookeeper.properties file from kafka_2.13-3.6.1/config, to start zookeeper.
Step 7: Start Kafka Server
- Open a PowerShell or Command Prompt.
- Change to the Kafka Windows folder:
cd C:\kafka_2.13-3.6.1\bin\windows
- Start Zookeeper from the Windows folder:
.\kafka-server-start.bat ../../config/server.properties
This command use windows bat file kafka-server-start.bat with server.properties file from kafka_2.13-3.6.1/config, to start the Kafka server.
Step 8: Create A Kafka Topic
- Open a PowerShell or Command Prompt.
- Change to the Kafka Windows folder:
cd C:\kafka_2.13-3.6.1\bin\windows
- Create a Kafka topic “my-topic” and hosted on localhost:9092:
.\kafka-topics.bat --create --topic my-topic --bootstrap-server localhost:9092
Step 9: Produce Messages To A Topic
- Create a Kafka producer:
.\kafka-console-producer.bat --topic my-topic --bootstrap-server localhost:9092
The given command using kafka-console-producer.bat
creates a Kafka producer for the “my-topic” topic, connecting to a local Kafka server on localhost:9092. The command prompt will prompt you to input the message you want to send to the Kafka topic.
Step 10: Read Messages From A Topic
- Open a PowerShell or Command Prompt.
- Change to the Kafka Windows folder:
cd C:\kafka_2.13-3.6.1\bin\windows
- Consume messages from Kafka topic:
.\kafka-console-consumer.bat --topic my-topic --from-beginning --bootstrap-server localhost:9092
The given command using kafka-console-consumer.bat
consumes messages from the “my-topic” Kafka topic, connecting to a local Kafka server on localhost:9092. The consumer will start reading messages from the beginning of the topic and display the input that was entered using the Kafka producer command.
Congratulations
You’ve successfully installed, configured, and started Apache Kafka on your Windows PC. Feel free to explore further and integrate Kafka into your projects.
Thank you for reading or watching, and if you found this tutorial helpful, please like, subscribe, and share. If you have any questions, leave them in the comments below. Happy coding!