In this project I'm demonstrating a simple architecture of microservices that perform distributed transactions. The example application applications are simple Spring Boot app that expose some HTTP endpoints for CRUD operations and connects to Postgres using Spring Data JPA.
All the examples are described in a separated articles on my blog. Here's a full list of available examples:
- Rollback or confirmation of distributed transaction across order-service, account-service and product-service. A detailed guide may be find in the following article: Distributed Transaction in Microservices with Spring Boot
- Start discovery-server. It is available on port 8761.
- Start RabbitMQ on Docker with command
docker run -d --name rabbit -h rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management
- Start transaction-server
- Start Postgres on Docker with command
docker run -d --name postgres -p 5432:5432 -e POSTGRES_USER=trx -e POSTGRES_PASSWORD=trx123 -e POSTGRES_DB=trx postgres
- Start microservices: account-service, product-service and order-service. The app order-service is listening on port 8080.
- Add some test data to product-service and account-service
- Send some tests requests. For example:
$ curl http://localhost:8080/orders -H "Content-Type: application/json" -d "{\"productId\":1, \"count\":10, \"customerId\":1}"
You can test all the apps on Docker. To do that first build the whole project using the following command:
$ mvn clean package -DskipTests -Pbuild-image
Then you can just run all the apps including RabbitMQ and Postgres with docker-compose
:
$ docker compose up