Event-driven microservices with asynchronous communication built with Laravel, Docker, and RabbitMQ. The admin API is using Laravel Passport for authentication.
Add a product to the admin microservice, and then it will be automatically dispatched and synced to the client microservice using RabbitMQ.
For each microservice: docker images are downloaded, and containers are built [App, Queue, Database] from the DockerFile.
After that the docker compose file runs a few [.sh]
files inside the container to prepare the microservice for work.
-
Install dependencies.
-
Create
[.env]
file. -
Run a command to initialize the laravel app:
- Generate an app key.
- Migrate the database.
Admin-only commands:
- Install dependencies.
- Create
[.env]
file. - Start the queue listener.
- Serve the Laravel app.
- RabbitMQ account https://www.cloudamqp.com/.
- Docker.
- Postman.
-
Make sure Docker is running.
-
Clone the repository.
$ git clone https://github.com/mostafaaminflakes/Using-RabbitMQ-in-Microservices.git
-
Populate
[.env.example]
with your RabbitMQ account details.RABBITMQ_HOST= RABBITMQ_USER= RABBITMQ_PASSWORD= RABBITMQ_VHOST=
-
Admin microservice.
$ cd Using-RabbitMQ-in-Microservices/admin $ docker compose up -d
-
Client microservice.
$ cd Using-RabbitMQ-in-Microservices/main $ docker compose up -d
- Import the collection file from /postman/collection.json into Postman.
- Navigate to
Authorization/Bearer Token
and add the token from this step above.
Depending on your internet speed, you may need need to run docker compose up -d
command twice at first time only to allow all dependencies to install properly. This is because the queue container depends on other containers to be ready to run.