A FastAPI and Apache Kafka project built in a Docker container
First of all, you need to configure your enviroment:
- Python
3.9
installed - Pip
3
installed - Java
8
installed - Docker installed
- Docker-compose installed
git init
git remote add origin https://github.com/harlemmuniz/kafka-fastapi-docker.git
git pull origin main
or
git init
git clone https://github.com/harlemmuniz/kafka-fastapi-docker.git
Installing Kafka and Kafdrop using docker compose in project/kafka folder:
cd /path/to/root/project/kafka
docker-compose up -d
Installing a Python virtual environment:
pip3 install virtualenv
Creating a Python virtual environment in the project root folder:
cd /path/to/root/project
virtualenv env
Activating the virtual environment:
source env/bin/activate
Installing the required libraries:
pip3 install fastapi aiokafka uvicorn
Starting the application (You should not use --reload
in production.):
uvicorn main:app --reload
If you want to run the project in Google Cloud, you will need to install the gunicorn:
pip3 install gunicorn