Microservices in a multimodule Maven project with Hexagonal Architecture, CQRS, and Kafka for synchronizing databases
Components
- Kafka [9092] + [9093]
- Kafka-UI [8080]
- REST API ms-artist with OpenApi Swagger and two separate DB for R/RW actions [8081]
- REST API ms-media with OpenApi Swagger and two separate DB for R/RW actions [8082]
- Redis DB in every microservice work as caches to store ID references for other REST APIs
graph RL
subgraph ms-artist
direction LR
subgraph ms-artist-ms
A{{ms-artist}}
end
subgraph ms-artist-db
direction LR
A1[(NoSql Read Db)]
A2[(Sql Write Db)]
A3[(Redis Backup Db)]
end
end
Kafka(((Kafka)))
KafkaUI(KafkaUI)
subgraph ms-media
direction RL
subgraph ms-media-ms
B{{ms-media}}
end
subgraph ms-media-db
direction RL
B1[(NoSql Read Db)]
B2[(Sql Write Db)]
B3[(Redis Backup Db)]
end
end
ms-media-db <--> ms-media-ms
ms-artist-db <--> ms-artist-ms
ms-artist -->|Publish| Kafka
Kafka -->|Subscriber| ms-artist
ms-media -->|Publish| Kafka
Kafka -->|Subscriber| ms-media
KafkaUI <--> Kafka
B1 <-.SYNCHRO.-> B2
A1 <-.SYNCHRO.-> A2
-
First of all clone or download the project.
-
Inside the main folder, you could find two docker-compose yaml files.
-
From there use the command line to start the project in dev or production mode
**Generate .jar**
mvn clean package
**Developer mode**
docker-compose -f docker-compose-dev.yml up -d
**Production mode**
docker-compose -f docker-compose-prod.yml up -d
The dev environment is ready for using with your IDE. The microservice attempts to communicate with Kafka using the local host. In production, it uses the archive Dockerfile to build an image of the project, so you wont need the IDE.
- You could stop the project and free resources with any of these orders
**Developer mode**
docker-compose -f docker-compose-dev.yml down --rmi local -v
**Production mode**
docker-compose -f docker-compose-prod.yml down --rmi local -v
First of all, please visit the REST API documentation. Replace ${port} for the suitable microservice port:
http://localhost:${port}/swagger-ui/index.html
Kafka-UI allow you to check your Kafka server using a practical dashboard, so visit the following url:
http://localhost:8080
Just me, Iván 😅