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,16 @@
$ mvn -pl saga test -Dtest=IdempotentConsumerTest
(the exact same ReserveInventoryCommand -- same commandId -- published twice by hand, to
simulate a redelivery; stock starts at 10, the command asks for 3)
ProcessedCommand rows for commandId f07ec35c-853c-4405-a024-b62d304dfabb: 1
Stock remaining for GADGET-DUP after two deliveries of the same command: 7
InventoryReply messages actually published: 1
reply: InventoryReply[commandId=f07ec35c-853c-4405-a024-b62d304dfabb, orderId=999, success=true, reason=null]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
Two deliveries, one row in processed_commands, one actual reservation: 10 - 3 = 7, not 4. The
second delivery hit IdempotencyGuard.claim(), got false back because the UNIQUE constraint on
commandId rejected the second insert, and returned from the listener before calling
InventoryService.tryReserve() at all -- it never touched stock, and it never published a second
InventoryReply. Exactly one reply reached the topic for two deliveries of the same command.