This project is structured around three distinct microservices that are developed using Django: warehouse, sales, and accounting.
For seamless asynchronous communication between these microservices, RabbitMQ has been employed. Each microservice has been encapsulated within its own Docker container. Furthermore, Docker has been utilized to host the MySQL database.
In addition to the core microservices, a mini-service has been developed using FastAPI to facilitate internal API calls to the microservices.
Before you can use this project, you need to have Docker installed on your system. Docker allows you to containerize and run applications in isolated environments. If you haven't already installed Docker, follow the instructions below based on your operating system:
Set up Docker's Apt repository:
sudo apt-get updatesudo apt-get install ca-certificates curl gnupgsudo install -m 0755 -d /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpgecho "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt-get update
Install the Docker packages:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Start the Docker service and enable it to start on boot:
sudo systemctl start dockersudo systemctl enable docker
Find out more on: https://docs.docker.com/engine/install/ubuntu/
- Download and install Docker Desktop
- Follow the installation instructions provided on the website.
- After installation, open Docker Desktop and ensure it's running.
You can find the docker desktop from: https://www.docker.com/products/docker-desktop/
cp warehouse/warehouse/template.env warehouse/warehouse/.env- Add details for host such as RABBIT_MQ_USER, RABBIT_MQ_PASSRABBIT_MQ_HOST in the .env file, Next run this command:
cd warehouse && docker-compose up- Admin URL: http://0.0.0.0:8001/admin
- API documentations: http://0.0.0.0:8001/api/v1/docs
cp accounting/accounting/template.env accounting/accounting/.env- Add details for host such as RABBIT_MQ_USER, RABBIT_MQ_PASSRABBIT_MQ_HOST in the .env file, Next run this command:
cd accounting && docker-compose up- Admin URL: http://0.0.0.0:8002/admin
- API documentations: http://0.0.0.0:8002/api/v1/docs
cp sales/sales/template.env sales/sales/.env- Add details for host such as RABBIT_MQ_USER, RABBIT_MQ_PASSRABBIT_MQ_HOST in the .env file, Next run this command:
cd sales && docker-compose up- Admin URL: http://0.0.0.0:8003/admin
- API documentations: http://0.0.0.0:8003/api/v1/docs
- Add the microservices URLs as environment variables in the docker-compose.yaml file located in the main directory with the following names: WAREHOUSE_URL, SALES_URL, and ACCOUNTING_URL.
cd main && docker-compose up- API documentations: http://0.0.0.0:8000/docs
- Run
docker-compose exec <image-name> shto execute a shell within a running container that is managed by Docker Compose - Run
python manage.py migrateto run the migrations of the microservice - Run
python manage.py createsuperto create a super-user to access the admin dashboard - Run
docker exec -it <volume-name> mysql -u root -pto access a MySQL database within a running in Docker container - Run
python -u consumer.pyto verify the RabbitMQ connection in terminal managed by Docker compose
Sometimes, we need a tool that creates a secure, publicly accessible tunnel URL to an application that's running on localhost. Especially, when we are implementing multiple microservices in same environment (localhost).
- Use ngrok for tunneling the URLs: https://ngrok.com
