This project demonstrates an event-driven architecture (EDA) implementation using Django and Kafka. It includes producers and consumers for handling events, integrated with Celery for asynchronous task management.
- Kafka integration for real-time message streaming.
- Django-based API for managing orders.
- Celery for handling background tasks.
- Docker support for containerized deployment.
EdaWithKafkaAndDjango-main/
├── .gitignore
├── docker-compose.yml
├── dockerfile
├── dockerfile.celery
├── manage.py
├── requirements.txt
├── EdaWithKafkaAndDjango/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
├── consumer/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── celery.py
│ ├── kafka_consumer.py
│ ├── models.py
│ ├── tasks.py
│ ├── tests.py
│ ├── views.py
│ ├── migrations/
│ └── __init__.py
├── order/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── kafka_producer.py
│ ├── models.py
│ ├── tasks.py
│ ├── tests.py
│ ├── urls.py
│ ├── views.py
│ ├── migrations/
│ ├── 0001_initial.py
│ ├── 0002_remove_order_order_id_alter_order_order_date.py
│ └── __init__.py
- Docker
- Python 3.9+
- Kafka server
-
Clone the Repository:
git clone https://github.com/yourusername/EdaWithKafkaAndDjango.git cd EdaWithKafkaAndDjango -
Build and Run Containers:
docker-compose up --build
-
Apply Migrations:
docker-compose exec web python manage.py migrate -
Start Kafka (if not already running): Ensure that Kafka broker and Zookeeper are running before testing.
-
Run the Development Server:
docker-compose exec web python manage.py runserver
-
Producer: The
orderapp produces Kafka messages when an order is created or updated. -
Consumer: The
consumerapp listens to Kafka topics and processes events accordingly. -
API: Endpoints for managing orders are available under the
orderapp's views.You can send an order by making a request to the following URL:
localhost:8000You can start consuming messages by making a request to the following URL:
localhost:8000/run_consumer
You can use the following vscode launch configurations for remote debugging in your IDE:
docker-compose.yml: Defines services for Django, Kafka, and Celery.consumer/kafka_consumer.py: Kafka consumer logic.order/kafka_producer.py: Kafka producer logic.
Feel free to submit issues or pull requests for improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
Developed with ❤️ using Django and Kafka.
{ "version": "0.2.0", "configurations": [ { "name": "Main App", "type": "python", "request": "attach", "host": "localhost", "port": 5679, "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/app" } ] }, ] }