OrderProcessSaga
The order process, after the classic eShop's OrderProcessor: it drives an order through the stock validation in the inventory context, and compensates when the inventory refuses.
onOrderSubmitted: a submitted order moves on to await its stock validation.
onStockStep: the order's steps in the inventory, in the order of its commits: an order awaiting its validation reserves each product's stock, its lines of one product added up; a cancelled order releases what the inventory reserved for it, a product reserved for nothing releasing nothing; a shipped order commits its reservations. The inventory is another context: the commands go to its command topic,
wow.eshop-inventory.commands.onReserveCommitted: a reservation the inventory commits comes back as a receipt on
wow.eshop-ordering.receiptsand confirms the order's product: the receipt names the stock, whose id is the product's.onReserveRejected: a reservation the inventory rejects (a short stock, a product it has no stock of) comes back as a receipt on the same topic and cancels the order.
onReserveCommitted is a hop of a wait chain: a checkout's Wow-Wait follows the reservations to their commit in the inventory, then their receipts back to it, and on into the confirmations it derives.
Each handler names only its target's id: the contract the inventory api's jar carries assigns the reservations to the inventory's stock (whose id is the product's), the ordering's own Manifest assigns the order's commands to the order, and each command is in the tenant of the commit or receipt it answers.
Functions
A release the inventory rejects for a product it has no stock of needs no compensation: that product reserved nothing either, so the handler accepts that code and derives nothing. Any other code is one it does not expect: the order parks at once, its reason naming the code, as without a handler.
A product the inventory reserved confirms it on the order that asked for it.
A product the inventory cannot reserve cancels the order that asked for it.
The order's steps in the inventory, from one handler of the order's commits: an order awaiting its validation reserves each product's stock, its lines of one product added up; a cancelled order releases what the inventory reserved for it, a product reserved for nothing releasing nothing; a shipped order commits its reservations. One subscription takes the order's commits in version order, and the next only once the commands of the one before are on the inventory's command topic, which keeps one stock's commands in that order: a release or a commit never reaches a stock before the order's reservation (#7427).