Add the saga module: Saga Pattern in Spring Boot, orchestration vs choreography with Kafka
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
$ mvn -pl saga test -Dtest=ChoreographyCompensationTest
|
||||
(same saga, stock deliberately too low: 1 unit on hand, order asks for 5)
|
||||
|
||||
Order 1 status: CANCELLED
|
||||
Stock remaining for GADGET-1 (untouched by the rejected reservation): 1
|
||||
Payment record status: REFUNDED
|
||||
|
||||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
|
||||
|
||||
InventoryChoreographyListener's tryReserve() refused before touching the stock map at all --
|
||||
the 1 unit is exactly where it started. That rejection published InventoryRejected, which
|
||||
PaymentChoreographyListener is also subscribed to; it refunded the payment it had reserved
|
||||
earlier and published PaymentRefunded, which OrderChoreographyListener used to cancel the
|
||||
order. The compensating transaction (the refund) is ordinary code in a class that already
|
||||
existed for an unrelated reason -- nothing new coordinates it.
|
||||
Reference in New Issue
Block a user