M1 is just responsible to validade and persist a user into the database. Then, a message is sent to the RabbitMQ (message-broker). All messages are put into a queue (FIFO).
Nowadays there are a lot of micro-services out there. One way to accomplish the communication between them is by using message-broker, such as RabbitMQ Kafka.
I have created two isolate micro-services as can be seen in the figure. The first micro-service (M2) was devised using Java Spring Boot.
M1 is just responsible to validade and persist a user into the database. Then, a message is sent to the RabbitMQ (message-broker). All messages are put into a queue (FIFO).
The second micro-service (M2) was implemented using Go and some nice libs such as: (i) cobra to create a command line interface, (ii) Viper to read .env files, (iii) GIN to provide a web-service, and (iv) Gocron to trigger a task periodically.
M2 consumes the EMAIL queue as a message is ready. Then, the message is unmarshalled and a welcome email is sent to the added user. Then, information weather the email was correctly send or not is persisted into the database. Using Gocron a task periodically check if there is any email that wasn’t sent - if so, we try to send the email again.
#golang #Java #SpringBoot #go #docker #rabbitmq
Important links:
M1 GitHub: link
M2 GitHub: link
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- docker compose
docker-compose up
- Clone the repo
git clone https://github.com/rdurelli/save-user-microservice-m1.git
- Install pom.xml packages
Start the SaveUserApplication.java. Then, call the following end-point to add an user:
POST http://localhost:9090/users
###REQUEST
{
"name": "Julia Fossaluzza",
"lastName": "Durelli",
"email" : "jubajuba.durelli@gmail.com",
"password": "secret"
}
###RESPONSE
{
"id": 15438,
"name": "Julia Fossaluzza",
"lastName": "Durelli",
"email": "jubajuba.durelli@gmail.com",
"created_date": "05/09/2021",
"last_modified_date": "05/09/2021"
}
Distributed under the MIT License. See LICENSE
for more information.
Rafael S. Durelli - @rafaeldurelli - rafael.durelli@ufla.br
Project Link: https://github.com/rdurelli/save-user-microservice-m1.git