Getting Kafka up and running without Docker on a Windows machine might seem like navigating a maze—most tutorials assume you're working on Linux or using containers. But what if you're working directly on Windows, or inside WSL, and want full visibility into every config and step?
I ran into the same challenge—and after hours of tweaking, testing, and debugging, I finally got it all working. This article documents the entire process, step-by-step, so you can skip the trial and error and get straight to building.
Let’s dive into the full local setup: from environment setup to producing and consuming messages with Python.
Step 1: Activate Your Python Virtual Environment
Make sure your virtual environment is activated:
F:\python_virtual_environments\orchestration_env\Scripts\activate
You should see your prompt change to:
(orchestration_env) F:\python_virtual_environments>
Step 2: Install the Kafka Python Library
With your virtual environment active, install:
pip install kafka-python
Verify:
python -c "import kafka; print(kafka.__version__)"
Step 3: Configure Kafka and Java Environment Variables
Kafka Variables:
- Open System Properties → Environment Variables.
- Add:
KAFKA_HOME = F:\kafka_2_13__3_4_0
- Add to
Path
:F:\kafka_2_13__3_4_0\bin\windows
Java Variables:
If not already set:
JAVA_HOME = C:\Program Files\Java\jdk-<version>
Restart your terminal to apply.
Step 4: Update Kafka Config Files
Navigate to:
F:\kafka_2_13__3_4_0\config
Edit zookeeper.properties:
clientPort=2182
Edit server.properties:
broker.id=0
zookeeper.connect=localhost:2182
log.dirs=F:/kafka_2_13__3_4_0/logs
Step 5: Delete meta.properties (Fix for InconsistentClusterId)
Stop Kafka:
F:\kafka_2_13__3_4_0\bin\windows\kafka-server-stop.bat
Stop Zookeeper:
F:\kafka_2_13__3_4_0\bin\windows\zookeeper-server-stop.bat
Delete meta.properties:
Navigate to: F:\kafka_2_13__3_4_0\logs
Delete the file: meta.properties
Step 6: Start Zookeeper
F:\kafka_2_13__3_4_0\bin\windows\zookeeper-server-start.bat F:\kafka_2_13__3_4_0\config\zookeeper.properties
Wait for Zookeeper to fully initialize.
Step 7: Start Kafka Broker
F:\kafka_2_13__3_4_0\bin\windows\kafka-server-start.bat F:\kafka_2_13__3_4_0\config\server.properties
Step 8: Create a Kafka Topic
F:\kafka_2_13__3_4_0\bin\windows\kafka-topics.bat -create -topic test-topic -bootstrap-server localhost:9092 -partitions 1 -replication-factor 1
Verify:
F:\kafka_2_13__3_4_0\bin\windows\kafka-topics.bat -list -bootstrap-server localhost:9092
Step 9: Use CMD for Producer and Consumer
Start Producer:
F:\kafka_2_13__3_4_0\bin\windows\kafka-console-producer.bat -topic test-topic -bootstrap-server localhost:9092
Type your messages in this window.
Start Consumer:
F:\kafka_2_13__3_4_0\bin\windows\kafka-console-consumer.bat -topic test-topic -bootstrap-server localhost:9092 -from-beginning
This window will show the messages received.
Step 10: Send & Receive Messages Using Python
Create Scripts:
kafka_producer.py
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
producer.send('test-topic', b'Hello from Python!')
producer.flush()
print("Message sent.")
kafka_consumer.py
from kafka import KafkaConsumer
consumer = KafkaConsumer(
'test-topic',
bootstrap_servers='localhost:9092',
auto_offset_reset='earliest',
group_id='test-group'
)
for message in consumer:
print(f"Received: {message.value.decode()}")
Run the Scripts:
Before running any Kafka-related Python scripts, first activate your
virtual environment:
F:\python_virtual_environments\orchestration_env\Scripts\activate
Once activated, your prompt will look like:
(orchestration_env) F:\python_virtual_environments>
Now, navigate to the Kafka scripts directory:
cd F:\kafka-scripts
Run the Producer script:
python kafka_producer.py
Then, open another CMD window, activate the virtual environment again, and run the Consumer script:
F:\python_virtual_environments\orchestration_env\Scripts\activate
cd F:\kafka-scripts
python kafka_consumer.py
Step 11: Stop Kafka and Zookeeper Safely
Once you're finished, stop both services gracefully:
F:\kafka_2_13__3_4_0\bin\windows\kafka-server-stop.bat
F:\kafka_2_13__3_4_0\bin\windows\zookeeper-server-stop.bat
🙌 Final Thoughts
Setting up Apache Kafka on Windows without Docker can feel tricky at first, but once you walk through the steps, it’s actually a clean and flexible solution — perfect for local development or experimentation.
If this guide helped you or saved you time, consider leaving a ❤️, bookmarking it for later, or sharing your experience in the comments.
I’d love to hear how it went for you — or answer any questions you might have!
Top comments (0)