diff --git a/AGENTS.md b/AGENTS.md
index 2a49339..d02f06e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -17,7 +17,7 @@ Article: none
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 a9eb1e5..a04cdc1 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 183 cases at about 99.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 198 cases at about 99.4%.
## 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 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:
- 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 and is not queued; a request without one is reserved with quantity 1. 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. 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:
-- 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" }
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..db686d8
--- /dev/null
+++ b/src/main/mule/eip/process-manager/process-manager-services.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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..7a4a7ef
--- /dev/null
+++ b/src/main/mule/eip/process-manager/process-manager.xml
@@ -0,0 +1,301 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ { 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 }
+ case "REFUND:FAILED" -> { status: "COMPENSATION_FAILED", 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"
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..60a2817
--- /dev/null
+++ b/src/test/munit/eip/process-manager-test-suite.xml
@@ -0,0 +1,738 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
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