Add the saga module: Saga Pattern in Spring Boot, orchestration vs choreography with Kafka

This commit is contained in:
Claude
2026-10-03 19:56:40 +00:00
parent c1b40b0db9
commit 4a5d3318bf
44 changed files with 1296 additions and 3 deletions
@@ -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.