From d26d0cf14a3d3c33cfa1b94de4e0e553445b02ee Mon Sep 17 00:00:00 2001 From: bruno souza Date: Wed, 21 Oct 2026 14:23:03 +0100 Subject: [PATCH 1/5] feat(eip): process manager keeps each order process's state in a persistent store and decides the next step from each asynchronous reply, with refund compensation and idempotent replies --- .../process-manager-services.xml | 66 +++++ .../eip/process-manager/process-manager.xml | 257 ++++++++++++++++++ src/main/resources/config/app.yaml | 5 + 3 files changed, 328 insertions(+) create mode 100644 src/main/mule/eip/process-manager/process-manager-services.xml create mode 100644 src/main/mule/eip/process-manager/process-manager.xml diff --git a/src/main/mule/eip/process-manager/process-manager-services.xml b/src/main/mule/eip/process-manager/process-manager-services.xml new file mode 100644 index 0000000..9f4a847 --- /dev/null +++ b/src/main/mule/eip/process-manager/process-manager-services.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + if (c.amount > (p('eip.processManager.paymentLimit') as Number)) "DECLINED" else "APPROVED" + case "STOCK" -> if ((c.sku default "") startsWith "SKU-OUT") "UNAVAILABLE" else "RESERVED" + case "INVOICE" -> "ISSUED" + else -> "REFUNDED" + }, + reference: vars.vStep ++ "-" ++ uuid() +}]]> + + + + + + + + + + + + + + diff --git a/src/main/mule/eip/process-manager/process-manager.xml b/src/main/mule/eip/process-manager/process-manager.xml new file mode 100644 index 0000000..4e45b93 --- /dev/null +++ b/src/main/mule/eip/process-manager/process-manager.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { status: "RUNNING", nextStep: "STOCK" } + case "PAYMENT:DECLINED" -> { status: "FAILED", nextStep: null } + case "STOCK:RESERVED" -> { status: "RUNNING", nextStep: "INVOICE" } + case "STOCK:UNAVAILABLE" -> { status: "COMPENSATING", nextStep: "REFUND" } + case "INVOICE:ISSUED" -> { status: "COMPLETED", nextStep: null } + case "REFUND:REFUNDED" -> { status: "CANCELLED", nextStep: null } + else -> null +}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/app.yaml b/src/main/resources/config/app.yaml index c4a8032..d635fa6 100644 --- a/src/main/resources/config/app.yaml +++ b/src/main/resources/config/app.yaml @@ -71,3 +71,8 @@ eip: # Message expiration: how often the consumer reads the queued stock reservation requests. messageExpiration: consumerFrequencyMillis: "1000" + # Process manager: payments above this amount are declined by the simulated payment service, and the + # manager's reply endpoint, where the simulated services post their asynchronous replies. + processManager: + paymentLimit: "1000" + replyPath: "/eip/process-manager/replies" From 4b54ed55c0fb1400d09417bee09d536d8a47fbf1 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Wed, 21 Oct 2026 14:23:03 +0100 Subject: [PATCH 2/5] test(eip): process manager suite over HTTP: completed, failed, cancelled with refund, duplicate, unknown and late replies, suspended command; polls instead of sleeping --- .../munit/eip/process-manager-test-suite.xml | 398 ++++++++++++++++++ 1 file changed, 398 insertions(+) create mode 100644 src/test/munit/eip/process-manager-test-suite.xml diff --git a/src/test/munit/eip/process-manager-test-suite.xml b/src/test/munit/eip/process-manager-test-suite.xml new file mode 100644 index 0000000..3e31863 --- /dev/null +++ b/src/test/munit/eip/process-manager-test-suite.xml @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ea27feec20ecfbdba1d7cd09d7fb2e943bfd9b57 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Wed, 21 Oct 2026 14:23:03 +0100 Subject: [PATCH 3/5] docs: wave 6 process manager in README, AGENTS.md and requests.http; 190 tests at 98.5% --- AGENTS.md | 2 +- README.md | 19 ++++++++++++++++--- requests.http | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 652229a..13ab86e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ Stack: Mule 4, MUnit, Maven A catalogue of runnable Mule 4 examples of design and integration patterns, one series per folder, each with MUnit tests and an accompanying article series. - **SOLID** (`solid/`, complete): before-and-after examples of the five SOLID principles. Each principle has a **before** endpoint that breaks the principle and an **after** endpoint that follows it, and MUnit tests show where the two behave the same and where the "before" version causes problems. -- **Enterprise Integration Patterns** (`eip/`, in progress): one folder and one MUnit suite per runnable pattern, using HTTP, object stores and the Scheduler only (and the Aggregators module for the aggregator), so the app runs with no external systems. Wave 1 (idempotent receiver, correlation identifier), wave 2 (content-based router, message filter, splitter, aggregator, recipient list, scatter-gather), wave 3 (message translator, canonical data model, content filter, claim check, content enricher) wave 4 (request-reply, return address, event-driven consumer, polling consumer, competing consumers, channel adapter) and wave 5 (guaranteed delivery, transactional client, message expiration, invalid message channel) are runnable; the patterns and their endpoints are listed in [README.md](README.md#enterprise-integration-patterns). Patterns that need a broker (publish-subscribe, dead letter channel, point-to-point channel) are documented with Anypoint MQ configuration in the wiki, not here; do not simulate a broker with VM queues. Object stores are in memory except the guaranteed delivery outbox, which is persistent by design; this app has no transactional connector, so the transactional client shows a compensation, not a rollback. +- **Enterprise Integration Patterns** (`eip/`, in progress): one folder and one MUnit suite per runnable pattern, using HTTP, object stores and the Scheduler only (and the Aggregators module for the aggregator), so the app runs with no external systems. Wave 1 (idempotent receiver, correlation identifier), wave 2 (content-based router, message filter, splitter, aggregator, recipient list, scatter-gather), wave 3 (message translator, canonical data model, content filter, claim check, content enricher) wave 4 (request-reply, return address, event-driven consumer, polling consumer, competing consumers, channel adapter) wave 5 (guaranteed delivery, transactional client, message expiration, invalid message channel) and wave 6 (process manager) are runnable; the patterns and their endpoints are listed in [README.md](README.md#enterprise-integration-patterns). Patterns that need a broker (publish-subscribe, dead letter channel, point-to-point channel) are documented with Anypoint MQ configuration in the wiki, not here; do not simulate a broker with VM queues. Object stores are in memory except the guaranteed delivery outbox and the process manager's process state and reply receipts, which are persistent by design; this app has no transactional connector, so the transactional client shows a compensation, not a rollback. HTTP endpoint paths are referenced by published articles; do not change them when moving files. diff --git a/README.md b/README.md index 4f1bd89..bce5b58 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ curl -s 'localhost:8081/lsp/before/orders/ORD-1001?provider=new' mvn clean test ``` -MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 181 cases at about 98.8%. +MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 190 cases at about 98.5%. ## SOLID in MuleSoft @@ -104,6 +104,12 @@ In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, | Invalid message channel | Invoice requests that are not JSON, are malformed JSON, are not an object or miss a field (`orderId`, positive `amount`, 3-letter `currency`) are kept in an invalid-message store with the reason, content type and body as received, never invoiced, and answered 400 naming the invalid message. A valid one is 202 `ACCEPTED`; a valid one whose `orderId` was already accepted is 409. The content type is compared in lower case (`Application/JSON` is JSON). Not the dead letter channel (the Dead Letter Channel page of the series, Anypoint MQ, no code here): that one receives valid messages that could not be delivered | [`eip/invalid-message-channel/`](src/main/mule/eip/invalid-message-channel) | `POST /eip/invoices/requests`, `GET /eip/invoices/requests/{orderId}`, `GET /eip/invoices/invalid-messages` | | Point-to-point channel | Documented with Anypoint MQ configuration in the wiki, not runnable here: one queue, each message consumed by one receiver, is a broker feature; in this app it would mean simulating a broker with VM queues. The one-receiver-per-message effect over a shared work list is shown by competing consumers (wave 4) | — | — | +**Wave 6, process manager:** + +| Pattern | Scenario | Code | Endpoints | +|---|---|---|---| +| Process manager | A POST (the trigger message) starts a process for an order and answers 202 `RUNNING` with a `processId`. The manager sends each step to a simulated service on this app (payment, stock reservation, invoice, refund), which answers 202 and replies later, from an Async scope, to the manager's reply endpoint with the `processId` (the correlation identifier of wave 1 over the asynchronous request-reply of wave 4). The process state (`status`, `currentStep`, `history` of commands and replies) is kept in an object store declared `persistent="true"`, and the manager decides the next step from each reply: payment `DECLINED` (amount above `eip.processManager.paymentLimit`, 1000) ends `FAILED`; stock `UNAVAILABLE` (sku `SKU-OUT...`) sends a refund, the compensation, and ends `CANCELLED`; all ok ends `COMPLETED`. A reply is applied once per process and step (`os:store failIfPresent` on a receipts store): a repeat while the process runs is 200 `DUPLICATE`, a reply for a step the process is not waiting for is 409, any reply for an ended process is 409, an unknown `processId` 404, an unknown outcome 400. A command that cannot be sent leaves the process `SUSPENDED` and answers 503. No timeout for a reply that never comes. Unlike a Routing Slip the sequence is not fixed up front. Overkill when every step answers synchronously: then one flow with a Choice per result and a Try for the refund is the orchestration | [`eip/process-manager/`](src/main/mule/eip/process-manager) | `POST /eip/process-manager/orders`, `POST /eip/process-manager/replies`, `GET /eip/process-manager/processes/{processId}`; simulated services: `POST /eip/process-manager/services/{payment\|stock\|invoice\|refund}` | + The MUnit suites are in [`src/test/munit/eip/`](src/test/munit/eip), one per pattern. What the wave 1 suites show, observed on Mule 4.9.17 with MUnit 3.7.1: - With no `objectStore`, the idempotent validator keeps IDs in memory for 5 minutes (the defaults in the 4.9.17 runtime's `IdempotentMessageValidator`). Three different orders posted over HTTP from one For Each give `accepted,duplicate,duplicate`; with `idExpression="#[payload.orderId]"` they give `accepted,accepted,accepted`. @@ -144,9 +150,13 @@ What the wave 5 suites show, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go - Message expiration: a request that expires in a minute is `QUEUED` until the consumer runs and then `RESERVED`; one sent already expired becomes `EXPIRED` with the reason and no reservation; one queued with `expiresAt` already past (the queue does not check it, only the consumer does, so no sleep is needed) is `EXPIRED` while one with a minute left in the same pass is `RESERVED`. A stored request whose `expiresAt` no longer parses becomes `FAILED` and the request after it is still `RESERVED` in the same run. A `quantity` of 0, -3, 1.5 or `"two"` gets 400. The Scheduler test polls (Until Successful) instead of sleeping. - Invalid message channel: malformed JSON, a schema violation (all three listed in the reason), an XML body and a JSON array each get 400 and one entry in the invalid channel with the reason and the body as received; the 400 names the same invalid-message id, and the request is not stored. A valid request is 202 and leaves the channel empty, also when sent as `Application/JSON; charset=UTF-8`; a second valid request with the same `orderId` gets 409 and the first is kept. +What the wave 6 suite shows, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go over HTTP to the app; the services reply on their own and the tests poll the state with Until Successful instead of sleeping): + +- Process manager: the happy path ends `COMPLETED` with the history `PAYMENT:SENT`, `PAYMENT:REPLY:APPROVED`, `STOCK:SENT`, `STOCK:REPLY:RESERVED`, `INVOICE:SENT`, `INVOICE:REPLY:ISSUED`; a payment of 5000 ends `FAILED` after the payment reply, with no stock or invoice step; a `SKU-OUT` order ends `CANCELLED` after `REFUND:REPLY:REFUNDED`, with no invoice. With the commands mocked (the services stay silent), the test sends the payment reply twice: 200 `APPLIED` then 200 `DUPLICATE`, applied once, and an invoice reply while the process waits for stock is 409. A reply or GET for an unknown `processId` is 404; after `COMPLETED` a late invoice or payment reply is 409 and the history keeps its six entries. An unknown outcome is 400 and does not move the process; a payment command that cannot be sent (mocked `HTTP:CONNECTIVITY`) answers 503 and leaves the process `SUSPENDED`, and a reply for it is then 409. + Notes: -- Object stores are in memory so every run starts clean, except the guaranteed delivery outbox, delivered and dead stores, declared persistent because surviving a restart is the point (the connector's guarantee; the suite clears them before each test). In production use a persistent, shared store (Object Store v2 on CloudHub): an in-memory store is lost on restart and is not shared between replicas. +- Object stores are in memory so every run starts clean, except the guaranteed delivery outbox, delivered and dead stores and the process manager's process and receipts stores, declared persistent because surviving a restart is the point (the connector's guarantee; the suites clear them before each test). In production use a persistent, shared store (Object Store v2 on CloudHub): an in-memory store is lost on restart and is not shared between replicas. - VM queues are not used to stand in for a broker: the VM connector is an in-application queue, not a message broker. - The aggregator keeps its groups in an object store too. In production, and always in a cluster, use a persistent, shared store, or a group whose items reach different workers never completes. @@ -221,7 +231,10 @@ src/main/mule/ message-expiration.xml queued requests with expiresAt, Scheduler consumer, expired requests invalid-message-channel/ invalid-message-channel.xml parse and field checks, invalid-message store with the reason -src/main/resources/config/app.yaml port, OCP payment routing, DIP repository choice, EIP self-call host, callback path, routing, claim check, request-reply, polling and competing consumers, guaranteed delivery and message expiration settings + process-manager/ + process-manager.xml trigger, reply endpoint with the next-step decision, persistent process state + process-manager-services.xml simulated payment, stock, invoice and refund services that reply asynchronously +src/main/resources/config/app.yaml port, OCP payment routing, DIP repository choice, EIP self-call host, callback path, routing, claim check, request-reply, polling and competing consumers, guaranteed delivery, message expiration and process manager settings src/main/resources/dwl/ translator/PartnerProducts.dwl partner product codes -> SKUs (message translator) canonical/ CanonicalOrder (type, validation), FromMarketplace, FromPartnerXml, ToInvoicing, ToWarehouse diff --git a/requests.http b/requests.http index fdc611d..aec1d97 100644 --- a/requests.http +++ b/requests.http @@ -343,3 +343,20 @@ Content-Type: application/json ### GET {{base}}/eip/invoices/invalid-messages + +### EIP process manager — start a process (amount above 1000 is declined; sku SKU-OUT... is out of stock), then read it +POST {{base}}/eip/process-manager/orders +Content-Type: application/json + +{ "orderId": "ORD-6101", "amount": 120, "sku": "SKU-BOOK", "quantity": 2 } + +### +# Replace PM-... with the processId from the response above +GET {{base}}/eip/process-manager/processes/PM-replace-me + +### +# A late reply after the process ended gets 409; an unknown processId 404 +POST {{base}}/eip/process-manager/replies +Content-Type: application/json + +{ "processId": "PM-replace-me", "step": "INVOICE", "outcome": "ISSUED" } From 0f6772bcca1221acb2ddcd4bfccdf41c6456c690 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Wed, 21 Oct 2026 15:17:10 +0100 Subject: [PATCH 4/5] fix(eip): protect process state and acknowledge applied replies --- .../process-manager-services.xml | 4 +- .../eip/process-manager/process-manager.xml | 102 +++-- .../munit/eip/process-manager-test-suite.xml | 348 +++++++++++++++++- 3 files changed, 420 insertions(+), 34 deletions(-) diff --git a/src/main/mule/eip/process-manager/process-manager-services.xml b/src/main/mule/eip/process-manager/process-manager-services.xml index 9f4a847..db686d8 100644 --- a/src/main/mule/eip/process-manager/process-manager-services.xml +++ b/src/main/mule/eip/process-manager/process-manager-services.xml @@ -19,7 +19,9 @@ payment APPROVED, or DECLINED when amount is above eip.processManager.paymentLimit (1000) stock RESERVED, or UNAVAILABLE when the sku starts with SKU-OUT invoice ISSUED; refund REFUNDED - A reply that fails to be sent is lost (logged) and the process stays waiting at the step. + A reply that fails to be sent is lost (logged) and the process stays waiting at the step (the suite's + pm-reply-lost-leaves-process-waiting shows it). The refund service always answers REFUNDED; REFUND + FAILED, which ends the process COMPENSATION_FAILED, is sent by the test itself. --> diff --git a/src/main/mule/eip/process-manager/process-manager.xml b/src/main/mule/eip/process-manager/process-manager.xml index 4e45b93..7a4a7ef 100644 --- a/src/main/mule/eip/process-manager/process-manager.xml +++ b/src/main/mule/eip/process-manager/process-manager.xml @@ -29,20 +29,35 @@ PAYMENT APPROVED -> STOCK PAYMENT DECLINED -> end FAILED STOCK RESERVED -> INVOICE STOCK UNAVAILABLE -> REFUND (compensation), COMPENSATING INVOICE ISSUED -> end COMPLETED REFUND REFUNDED -> end CANCELLED - Replies: unknown processId 404; a process already ended (COMPLETED, FAILED, CANCELLED, SUSPENDED) 409, - late or repeated replies included; a reply for a step the process is not waiting for 409; a repeated - reply for the step it is waiting for, while a race is still possible, 200 DUPLICATE and nothing changes. + REFUND FAILED -> end COMPENSATION_FAILED + Replies: unknown processId 404; a process not accepting replies (FAILED, CANCELLED, COMPLETED, + COMPENSATION_FAILED, SUSPENDED) 409, late or repeated replies included; a reply for a step the process + is not waiting for, and never received, 409; a repeated reply for a step already applied, while the + process runs, is 200 DUPLICATE and nothing changes; the same step with a different outcome than the one + applied is 409 "Conflicting reply". A reply is applied once per process and step: os:store with failIfPresent="true" on a receipts store claims processId:step, and "If the parameter is set to true, then an OS:KEY_ALREADY_EXISTS error is thrown instead" (https://docs.mulesoft.com/object-store-connector/latest/object-store-connector-reference), - so of two copies arriving together only one moves the process on. Across workers that holds only in a - Mule cluster (same page). + so of two copies arriving together only one moves the process on (the suite sends two copies at once + over HTTP and holds both just before the claim, so the second one meets KEY_ALREADY_EXISTS). Across + workers that holds only in a Mule cluster (same page). + The state itself is read, changed and written back with no lock beyond that receipt claim: the claim + serialises replies for one step, and the SUSPENDED write re-reads the state and only suspends when + currentStep and history are still the ones it sent (compare-and-set), otherwise it keeps the newer state. + That holds on one worker only; a re-read and a write are two operations, not one atomic step. The state lives in Object Stores declared persistent="true", so a process that waits for a reply for hours survives a restart (the connector's guarantee, not shown by MUnit). There is no timeout here: a reply that never comes leaves the process waiting at its step; a real manager needs a Scheduler that looks for processes waiting too long. A step command that cannot be sent leaves the process SUSPENDED - with the error and answers 503. + with the error: the start endpoint answers 503 with the processId in the body; the reply endpoint, whose + reply was applied, answers 200 APPLIED with status SUSPENDED (the replying service did its part). A + refund that fails ends the process COMPENSATION_FAILED. SUSPENDED and COMPENSATION_FAILED both need + recovery by hand or by a Scheduler; this example has no resume endpoint. + + Neither store has a TTL by default; the connector reference (link above) describes entryTtl and + expirationInterval for expiring entries. The receipts store keeps receipts 7 days (entryTtl); the + process store keeps every process, so in production give it a TTL or a cleanup job too. WHEN IT IS OVERKILL: if every step answers synchronously within one request, a single flow that calls payment, stock and invoice in sequence, with a Choice on each result and a Try for the refund, is the @@ -60,7 +75,7 @@ No broker is simulated: the commands and the replies are HTTP calls to this app. --> - + @@ -89,10 +104,18 @@ output application/java - + + + + + + + + + - + @@ -110,13 +133,15 @@ output application/java - + - - - - + + + + + + @@ -128,15 +153,19 @@ output application/java - - + + - - + + + + + + @@ -151,6 +180,15 @@ output application/java + + + + + + + + + @@ -164,6 +202,7 @@ output application/java case "STOCK:UNAVAILABLE" -> { status: "COMPENSATING", nextStep: "REFUND" } case "INVOICE:ISSUED" -> { status: "COMPLETED", nextStep: null } case "REFUND:REFUNDED" -> { status: "CANCELLED", nextStep: null } + case "REFUND:FAILED" -> { status: "COMPENSATION_FAILED", nextStep: null } else -> null }]]> @@ -208,7 +247,7 @@ vars.vState ++ { - + - - - - - + + + + + + + + + + + + + + + - - - - - diff --git a/src/test/munit/eip/process-manager-test-suite.xml b/src/test/munit/eip/process-manager-test-suite.xml index 3e31863..60a2817 100644 --- a/src/test/munit/eip/process-manager-test-suite.xml +++ b/src/test/munit/eip/process-manager-test-suite.xml @@ -20,9 +20,13 @@ --> + + + + @@ -265,7 +269,7 @@ - + @@ -331,7 +335,7 @@ - + @@ -355,13 +359,13 @@ - + - + @@ -370,12 +374,348 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 1e9c0874f08bb488594f391e3b2203c038046474 Mon Sep 17 00:00:00 2001 From: bruno souza Date: Wed, 21 Oct 2026 15:17:10 +0100 Subject: [PATCH 5/5] docs(eip): describe process manager recovery and reviewed HTTP cases --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bce5b58..fa1f2e8 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ curl -s 'localhost:8081/lsp/before/orders/ORD-1001?provider=new' mvn clean test ``` -MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 190 cases at about 98.5%. +MUnit runs on the Mule Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in `~/.m2/settings.xml`, as in any MuleSoft project). The build fails below 80% application coverage; the current suites cover 196 cases at about 98.9%. ## SOLID in MuleSoft @@ -108,7 +108,7 @@ In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, | Pattern | Scenario | Code | Endpoints | |---|---|---|---| -| Process manager | A POST (the trigger message) starts a process for an order and answers 202 `RUNNING` with a `processId`. The manager sends each step to a simulated service on this app (payment, stock reservation, invoice, refund), which answers 202 and replies later, from an Async scope, to the manager's reply endpoint with the `processId` (the correlation identifier of wave 1 over the asynchronous request-reply of wave 4). The process state (`status`, `currentStep`, `history` of commands and replies) is kept in an object store declared `persistent="true"`, and the manager decides the next step from each reply: payment `DECLINED` (amount above `eip.processManager.paymentLimit`, 1000) ends `FAILED`; stock `UNAVAILABLE` (sku `SKU-OUT...`) sends a refund, the compensation, and ends `CANCELLED`; all ok ends `COMPLETED`. A reply is applied once per process and step (`os:store failIfPresent` on a receipts store): a repeat while the process runs is 200 `DUPLICATE`, a reply for a step the process is not waiting for is 409, any reply for an ended process is 409, an unknown `processId` 404, an unknown outcome 400. A command that cannot be sent leaves the process `SUSPENDED` and answers 503. No timeout for a reply that never comes. Unlike a Routing Slip the sequence is not fixed up front. Overkill when every step answers synchronously: then one flow with a Choice per result and a Try for the refund is the orchestration | [`eip/process-manager/`](src/main/mule/eip/process-manager) | `POST /eip/process-manager/orders`, `POST /eip/process-manager/replies`, `GET /eip/process-manager/processes/{processId}`; simulated services: `POST /eip/process-manager/services/{payment\|stock\|invoice\|refund}` | +| Process manager | A POST (the trigger message) starts a process for an order and answers 202 `RUNNING` with a `processId`. The manager sends each step to a simulated service on this app (payment, stock reservation, invoice, refund), which answers 202 and replies later, from an Async scope, to the manager's reply endpoint with the `processId` (the correlation identifier of wave 1 over the asynchronous request-reply of wave 4). The process state (`status`, `currentStep`, `history` of commands and replies) is kept in an object store declared `persistent="true"`, and the manager decides the next step from each reply: payment `DECLINED` (amount above `eip.processManager.paymentLimit`, 1000) ends `FAILED`; stock `UNAVAILABLE` (sku `SKU-OUT...`) sends a refund, the compensation, and ends `CANCELLED`; all ok ends `COMPLETED`. A refund `FAILED` ends `COMPENSATION_FAILED`. A reply is applied once per process and step (`os:store failIfPresent` on a receipts store whose entries expire after 7 days): a repeated reply for a step already applied, while the process runs, is 200 `DUPLICATE`; the same step with a different outcome is 409 `Conflicting reply`; a reply for a step the process is not waiting for is 409; a process not accepting replies (`FAILED`, `CANCELLED`, `COMPLETED`, `COMPENSATION_FAILED`, `SUSPENDED`) answers 409; an unknown `processId` 404, an unknown outcome 400. A command that cannot be sent leaves the process `SUSPENDED`: the start answers 503 with the `processId` in the body, the reply endpoint (whose reply was applied) 200 `APPLIED` with status `SUSPENDED`. The suspend re-reads the state and only suspends when nothing moved it on (compare-and-set); there is no other lock on the state, and that holds on one worker only. `SUSPENDED` and `COMPENSATION_FAILED` need recovery by hand or by a Scheduler; there is no resume endpoint. No timeout for a reply that never comes. Unlike a Routing Slip the sequence is not fixed up front. Overkill when every step answers synchronously: then one flow with a Choice per result and a Try for the refund is the orchestration | [`eip/process-manager/`](src/main/mule/eip/process-manager) | `POST /eip/process-manager/orders`, `POST /eip/process-manager/replies`, `GET /eip/process-manager/processes/{processId}`; simulated services: `POST /eip/process-manager/services/{payment\|stock\|invoice\|refund}` | The MUnit suites are in [`src/test/munit/eip/`](src/test/munit/eip), one per pattern. What the wave 1 suites show, observed on Mule 4.9.17 with MUnit 3.7.1: @@ -152,7 +152,7 @@ What the wave 5 suites show, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go What the wave 6 suite shows, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go over HTTP to the app; the services reply on their own and the tests poll the state with Until Successful instead of sleeping): -- Process manager: the happy path ends `COMPLETED` with the history `PAYMENT:SENT`, `PAYMENT:REPLY:APPROVED`, `STOCK:SENT`, `STOCK:REPLY:RESERVED`, `INVOICE:SENT`, `INVOICE:REPLY:ISSUED`; a payment of 5000 ends `FAILED` after the payment reply, with no stock or invoice step; a `SKU-OUT` order ends `CANCELLED` after `REFUND:REPLY:REFUNDED`, with no invoice. With the commands mocked (the services stay silent), the test sends the payment reply twice: 200 `APPLIED` then 200 `DUPLICATE`, applied once, and an invoice reply while the process waits for stock is 409. A reply or GET for an unknown `processId` is 404; after `COMPLETED` a late invoice or payment reply is 409 and the history keeps its six entries. An unknown outcome is 400 and does not move the process; a payment command that cannot be sent (mocked `HTTP:CONNECTIVITY`) answers 503 and leaves the process `SUSPENDED`, and a reply for it is then 409. +- Process manager: the happy path ends `COMPLETED` with the history `PAYMENT:SENT`, `PAYMENT:REPLY:APPROVED`, `STOCK:SENT`, `STOCK:REPLY:RESERVED`, `INVOICE:SENT`, `INVOICE:REPLY:ISSUED`; a payment of 5000 ends `FAILED` after the payment reply, with no stock or invoice step; a `SKU-OUT` order ends `CANCELLED` after `REFUND:REPLY:REFUNDED`, with no invoice. With the commands mocked (the services stay silent), the test sends the payment reply twice: 200 `APPLIED` then 200 `DUPLICATE`, applied once, and an invoice reply while the process waits for stock is 409. Two copies of the payment reply sent at once from a Scatter-Gather, each held just before the receipt claim until the other has read the state, get one `APPLIED` and one `DUPLICATE` (the second claim meets `OS:KEY_ALREADY_EXISTS`) and the history has one payment reply. A payment reply `DECLINED` after `APPROVED` was applied is 409 `Conflicting reply: PAYMENT was applied as APPROVED, not DECLINED`. A reply or GET for an unknown `processId` is 404; after `COMPLETED` a late invoice or payment reply is 409 and the history keeps its six entries. An unknown outcome is 400 and does not move the process; a payment command that cannot be sent (mocked `HTTP:CONNECTIVITY`) answers 503 with the `processId` and `SUSPENDED` in the body and leaves the process `SUSPENDED`, and a reply for it is then 409. When the payment reply is applied (a spy writes the newer state) before the send error is handled, the process stays `RUNNING` at `STOCK`. A payment reply whose stock command cannot be sent gets 200 `APPLIED` with status `SUSPENDED`. A refund reply `FAILED` ends `COMPENSATION_FAILED` and a later reply is 409. A reply the payment service cannot deliver (reply endpoint mocked unreachable) is logged and the process stays `RUNNING` at `PAYMENT`. Notes: