This project demo saga distributed transactions how to work in Microservices with Kafka and Spring Boot
There microservices show as below:
Order-Service- it is gateway service to send new order events to the Kafka topic and process of a distributed transactionPayment-Service- it performs local transaction on the customer account to perform paymentorderpriceInventory-Service- it performs local transaction on the inventory basing on number of products byorder
Here's the diagram with architecture:
Order-Servicesend a newOrder->OrderStatus.NEWPayment-ServiceandInventory-ServicereceiveOrderand handle it by performing a local transaction on the dataPayment-ServiceandInventory-Servicesend a responseOrder->OrderStatus.ACCEPTorOrderStatus.REJECTOrder-Serviceprocess incoming stream of orders fromPayment-ServiceandInventory-Service, join them byOrderid and sends Order with a new status ->OrderStatus.CONFIRMEDorOrderStatus.ROLLBACKorOrderStatus.REJECTEDPayment-ServiceandInventory-Servicereceive Order with a final status and "commit" or "rollback" a local transaction make before
- Startup the Database, Kafka
docker-compose up -d ./docker/docker-compose.yml- Startup Microservices
Order-ServicePayment-ServiceInventory-Service
- Send one order:
curl --location --request POST 'http://localhost:18080/orders' --header 'Content-Type: application/json' --data-raw '{
"customerId": 10,
"productId": 10,
"productCount": 5,
"price": 100,
"status": "NEW"
}'- Random generate orders:
curl --location --request POST 'http://localhost:18080/orders/generate'- Search order result by API:
curl --location --request GET 'http://localhost:18080/orders'- View order result by
kafka-ui, visithttp://localhost:9021
