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 paymentorder
priceInventory-Service
- it performs local transaction on the inventory basing on number of products byorder
Here's the diagram with architecture:
Order-Service
send a newOrder
->OrderStatus.NEW
Payment-Service
andInventory-Service
receiveOrder
and handle it by performing a local transaction on the dataPayment-Service
andInventory-Service
send a responseOrder
->OrderStatus.ACCEPT
orOrderStatus.REJECT
Order-Service
process incoming stream of orders fromPayment-Service
andInventory-Service
, join them byOrder
id and sends Order with a new status ->OrderStatus.CONFIRMED
orOrderStatus.ROLLBACK
orOrderStatus.REJECTED
Payment-Service
andInventory-Service
receive 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-Service
Payment-Service
Inventory-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