paint-brush
A Beginner's Guide to Starting Apache Kafka on Windows 10 (Kafka v3.4)by@sumithkpuri
362 reads
362 reads

A Beginner's Guide to Starting Apache Kafka on Windows 10 (Kafka v3.4)

by Sumith PuriJuly 19th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Apache Kafka Version 3.4.0 was Released on February 7, 2023, This Article specifically is for the Kafka Version (3. 4). For Purposes of this Article, I use {KAFKA_HOME} as the Windows Folder where Kafka was installed.
featured image - A Beginner's Guide to Starting Apache Kafka on Windows 10 (Kafka v3.4)
Sumith Puri HackerNoon profile picture

This is part one of a two-series on running the Apache Kafka server. All this is demonstrated step-by-step from the command line. All of this is for Apache Kafka v3.4 on Windows 10.



Pre-Requisites

1. Install Java//JRE (v8.0 is used in this Example)

2. Install Apache Kafka 3.4.0 from the Given Link

3. Set Java Classpath> Set JAVA_HOME Correctly

4. UnZIP/UnTAR Apache Kafka Downloaded in (2)

5. Use a Text Editor like [Notepad++] for Editing




Version 3.4.0

Apache Kafka Version 3.4.0 was Released on Feb 7, 2023, This article specifically is for the Kafka Version (2.13-3.4.0). For the purpose of this Article, I use {KAFKA_HOME} as the Windows folder where Kafka was installed.




Step-By-Step Guide


0. Configure Zookeeper (Data Directory)

Create a folder to hold Zookeeper Data by modifying the file zookeper.properties (File is Located under {KAFKA_HOME}/config/). Create a Folder named zk-data (or as per your wish). In my case, I created this under {KAFKA_HOME}. You may then modify your properties file as shown in the image below.  Modify your dataDir to point to the newly created folder.


Configure Zookeeper



0. Configure Kafka (Kafka Logs)

For the purpose of Kafka logs, you can create a folder with the name kafka-logs. In my case, I created this under {KAFKA_HOME}. You may then modify your properties file as shown in the image below. The property to be modified is log.dirs in server.properties which should now point to the newly created folder.


Configure Kafka



1. Starting Zookeeper

First, Zookeeper has to be started using the following command.

zookeeper-server-start.bat ..\..\config\zookeeper.properties

Starting Zookeeper



2. Starting Kafka Server

Next, we will start the Kafka Server using the following command.

D:\kafka_2.13-3.4.0\bin\windows>kafka-server-start.bat ..\..\config\server.properties

Starting Kafka Server



3. Creating a Test Topic

Create a Kafka Topic to test out the Kafka Installation using the following command.

D:\kafka_2.13-3.4.0\bin\windows>kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

Creating a Test Topic

The above is an updated way to create topics in Kafka. In earlier versions of Kafka (Kafka v2), the suggested way to create topics was directly via Zookeeper. From v3, It has changed to create topics via Brokers.


(Cited from StackOverflow)

For ver 2.* you have to create the topic using Zookeper with the default port 2181 as a parameter. For ver 3.* the zookeeper is not a parameter, you must use --bootstrap-server using localhost or the IP address of the server and the default port 9092.

Documentation




4. Create Kafka Producer

kafka-console-producer.bat --broker-list localhost:9092 --topic test

Create Kafka Producer



5. Create Kafka Consumer

kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

Create Kafka Consumer



Next in this series of articles will be the demonstration of a Core Java Kafka Producer and Consumer, followed by an article on Spring Boot-based Kafka Integration.


Also published here.