This code is a test using 2 microservices using RabbitMQ, NodeJS, Express, MySQL, Prisma, JWT.
- Have Node installed;
- Have Docker installed;
In the root folder, load docker with the command:
docker-compose -f "docker-compose.yaml" up -d --build
The microservices are running outside of docker. Enter the service1 and service2 folders and run in each one:
npm install
npx prisma migrate dev
npx prisma migrate
This command will create the database for each microservice.
To run the systems, with the terminal on each separate run:
npm run dev
That way the 2 services will be running on their proper terminals.
To access RabbitMQ use http://localhost:15672/ the Username and Password are admin
.
The service1 has one Post Request at http://localhost:3000/newproduct and the body:
{
"name": "test1",
"bar_code": "10",
"price": 15.20,
"quantity": 3
}
If using Postman, just import the file Node_with_RabbitMQ.postman_collection.json
In this example, service1 will add at his DB the product without quantity and will send through RabbitMQ to service2 the quantity and the ID. Service2 will add to his DB and send a response through RabbitMQ. This is the RPC method.
To create a new user, use the route http://localhost:3000/newuser and the body:
{
"email" : "[email protected]",
"password": "12345"
}
Make login in http://localhost:3000/login with the same body ahead. The response will have the JWT token. Use it in Authorization, Bearer Token.
If this code helped you, fell free to pay me a coffee :D
This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.