Friday, August 25, 2023

Kafka setup in window

Here's a step-by-step guide on how to do it: 1. Prerequisites: Before you begin, make sure you have the following prerequisites installed on your Windows system: Java Development Kit (JDK) 8 or later: Kafka requires Java to run. You can download it from the Oracle website or use OpenJDK.

2. Download Apache Kafka:

Visit the Apache Kafka website (https://kafka.apache.org/downloads) and download the latest stable version of Kafka for Windows. Choose the "binary" download.

3. Extract Kafka:

Extract the downloaded Kafka archive to a directory of your choice. For example, you can create a folder called kafka on your C: drive and extract the contents there.

4. Configure Kafka:

Kafka requires a few configuration changes for Windows:

Open the config/server.properties file in a text editor and set the log.dirs property to a directory that exists on your Windows system. For example, log.dirs=C:/kafka/data.

5. Start ZooKeeper (Kafka dependency):

Kafka relies on Apache ZooKeeper. Open a Command Prompt and navigate to the Kafka directory.

bash
cd C:\kafka

Start ZooKeeper using the following command:

bash
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties

6. Start Kafka:

In a new Command Prompt window (while keeping the ZooKeeper window open), navigate to the Kafka directory again.

bash
cd C:\kafka

Start Kafka using the following command:

bash
.\bin\windows\kafka-server-start.bat .\config\server.properties

7. Create Kafka Topics:

You can use the Kafka command-line tools to create topics. For example, to create a topic named "mytopic," open a new Command Prompt window and navigate to the Kafka directory:

bash
cd C:\kafka

Run the following command to create a topic:

bash
.\bin\windows\kafka-topics.bat --create --topic mytopic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1

8. Produce and Consume Messages:

You can use the Kafka command-line tools to produce and consume messages as well. For example, to produce a message to the "mytopic" topic:

bash
.\bin\windows\kafka-console-producer.bat --topic mytopic --bootstrap-server localhost:9092

To consume messages from the "mytopic" topic:

bash
.\bin\windows\kafka-console-consumer.bat --topic mytopic --bootstrap-server localhost:9092 --from-beginning

9. Stop Kafka and ZooKeeper:

To stop Kafka and ZooKeeper, you can press Ctrl + C in their respective Command Prompt windows.

That's it! You now have a basic Kafka setup running on your Windows system for local development.




No comments:

Post a Comment

Kafka setup in window

Here's a step-by-step guide on how to do it : 1. Prerequisites : Before you begin, make sure you have the following prerequisites inst...