This is a simple project, made to understand the basics of Kafka.
The project was made using this video as reference: Kafka Crash Course - Hands-On Project
The project consists in 3 parts:
- A producer
- A Kafka node
- A consumer
Once it's all set up, the data flows like this:
- The
producerpublishes a food order in Kafka "orders" topic, simulating an user interacting with the system; - The
consumerconstantly polls the "orders" topic in Kafka, searching for new orders; Kafkareturns the order to theconsumer;- The
consumerthen prints it in the console
You need to have Docker and Python installed
- Ceate a python
venv:
python -m venv .venv- Activate the
venvyou just created:
Linux:
source .venv/bin/activateWindows:
.venv\Scripts\activate- Install dependencies:
pip install uv
uv sync- Run Kafka with the
docker-compose.yamlfile:
docker compose up -dFor the python commands below, remember to run in a terminal with the
venvactivated
- Run the
consumerfor it to keep listening:
python consumer.py- In another terminal, run the
producer(it should publish an order, log in the console and exit the program):
python producer.pyEvery single time you run the
producer, theconsumershould read the order inKafkaand print it in the console
