Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) 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.
- **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, and the File connector on the local disk for the file transfer), 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), wave 6 (process manager) and wave 7 (wire tap, file transfer) 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.

Expand All @@ -31,6 +31,7 @@ EIP examples use Bruno's MuleSoft naming rules (BRU-NAME-1 to BRU-NAME-3, `packs
- `mule.http.connector.version = 1.11.3` — [pom.xml](pom.xml).
- `mule.objectstore.connector.version = 1.3.2` — [pom.xml](pom.xml).
- `mule.aggregators.module.version = 1.1.5` — [pom.xml](pom.xml).
- `mule.file.connector.version = 1.5.7` — [pom.xml](pom.xml).
- `Declared minimum Mule runtime 4.9.0` — [mule-artifact.json](mule-artifact.json).

These are source declarations, not evidence of installed runtimes. Maven properties may describe build/test dependencies rather than supported runtime minima; unresolved expressions remain inherited until verified.
Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 198 cases at about 99.4%.
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 228 cases at about 99.4%.

## SOLID in MuleSoft

Expand All @@ -55,7 +55,7 @@ Notes:

## Enterprise Integration Patterns

In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, implemented in Mule 4 around one scenario: an order is routed, charged and paid by a payment provider, its stock is reserved, and it is invoiced. Every runnable example uses HTTP, DataWeave and object stores only (plus the Aggregators module for the aggregator), so it needs no broker and no external system.
In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, implemented in Mule 4 around one scenario: an order is routed, charged and paid by a payment provider, its stock is reserved, and it is invoiced. Every runnable example uses HTTP, DataWeave and object stores only (plus the Aggregators module for the aggregator and the File connector, on the local disk, for the file transfer), so it needs no broker and no external system.

**Wave 1, messaging and reliability:**

Expand Down Expand Up @@ -114,6 +114,13 @@ In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*,
|---|---|---|---|
| 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}` |

**Wave 7, wire tap and file transfer:**

| Pattern | Scenario | Code | Endpoints |
|---|---|---|---|
| Wire tap | Every order is copied to a (simulated) audit system that can be slow or switched off. **Before:** the copy is written inline, so audit down fails the order (503; 504 on a timeout, after which the audit system may still record a copy of the order that was not accepted) and audit slow delays it. **After:** an Async scope with its own Try sends the payload as received; the order is accepted (201) whether the audit system is up, slow or down, and nothing the branch does to its payload or variables reaches the main flow. **The tap is lossy:** a refused copy, or one in memory when the app stops, is gone; after a timeout the outcome is unknown (the copy may still arrive, as it does here) and the tap does not retry; for a copy that must not be lost use guaranteed delivery. `maxConcurrency` is not set on the scope (see the header comment of `wire-tap.xml`) | [`eip/wire-tap/`](src/main/mule/eip/wire-tap) | `POST /eip/wire-tap/inline/orders`, `POST /eip/wire-tap/orders`, `PUT /eip/wire-tap/audit/availability`, `GET /eip/wire-tap/audit/copies` (and `POST /eip/wire-tap/audit/copies`, the simulated audit system) |
| File transfer (an integration style) | A producer writes a CSV file of orders under a temporary name and renames it; a File connector listener, matching only the final name and only regular files (no directories or symbolic links), reads it, records the rows and moves it to `processed`, or to `error` when any row is invalid. A failed run leaves the file in the inbox for the next poll. A name still waiting, or being written by another request, is refused (409); a name that arrives again is archived under a unique name, so nothing is overwritten. Directories are `eip.fileTransfer.*` in `app.yaml`: the inbox must exist at startup and defaults to the OS temporary directory, processed and error default to folders under it; on a shared temporary directory none of the three is private (with the sticky bit, as on Linux `/tmp`, another user's file or hard link with a matching name is imported, and a file the app cannot move is read again on every poll for as long as the app runs), so point them elsewhere outside a demo. Local disk only: on CloudHub it is ephemeral and private to a replica | [`eip/file-transfer/`](src/main/mule/eip/file-transfer) | `POST /eip/billing/exports`, `GET /eip/billing/imports`, `GET /eip/billing/rejected-files` |

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`.
Expand Down Expand Up @@ -158,6 +165,11 @@ What the wave 6 suite shows, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go

- 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`.

What the wave 7 suites show, observed on Mule 4.9.17 with MUnit 3.7.1 and File connector 1.5.7:

- Wire tap: with the audit system off the inline version answers 503 and does not accept the order, and the tapped version answers 201 and logs the copy as not confirmed; the refused copy is not sent again once the system is back. With the audit system 3000 ms slow the tapped order is answered before the copy arrives. With it slower than the 5000 ms timeout, the inline order gets 504 and is not accepted, the tapped order is accepted, and in both the copy is recorded afterwards. A mocked tap call that rewrites the branch's payload and variables changes neither the main flow's answer nor its variables.
- File transfer: a half-written file under its temporary name is still there, unread, after several polls; at the moment of the rename the inbox holds only the complete temporary file. A second export of a name still waiting, or one being written, gets 409; concurrent exports of different ids are all accepted, and of concurrent exports of one id exactly one is. A failed publication leaves no temporary file; a nested order field gets 400; a symbolic link or a directory with a matching name is not read; the same name sent again after consumption leaves two files in `processed` under different names. When recording the rows fails, the file stays in the inbox and is read again; it is neither processed nor rejected.

Notes:

- 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.
Expand All @@ -168,7 +180,7 @@ Notes:

```
src/main/mule/
global.xml shared: HTTP listener, properties, error handler (400/404/409/503 as JSON)
global.xml shared: HTTP listener, properties, error handler (400/404/409/503/504 as JSON)
solid/ SOLID in MuleSoft
srp/ ocp/ lsp/ isp/ dip/
<principle>-before.xml
Expand Down Expand Up @@ -238,10 +250,16 @@ src/main/mule/
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
wire-tap/
wire-tap.xml inline audit write (before) vs Async tap with its own error handler (after)
wire-tap-audit.xml simulated audit system that can be slow or switched off
file-transfer/
file-transfer.xml CSV producer (temporary name, rename), File listener consumer, results lookup
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, wire tap, file transfer 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
src/test/java/ test helper that creates a symbolic link (file transfer suite)
src/test/munit/
solid/<principle>-test-suite.xml
eip/<pattern>-test-suite.xml
Expand Down
6 changes: 5 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flowchart LR
Solid --> Sim[Simulated systems inside the app]
Eip --> Sim
Eip --> Store[(Object stores)]
Eip --> Dir[(Local directories, file transfer)]
Config[config/app.yaml] -.-> App
Articles[Articles on brunosouzas.com] -.->|cite paths and endpoints| App
```
Expand Down Expand Up @@ -51,10 +52,13 @@ The open/closed example uses the same idea: `payment.flow.<method>` in `app.yaml
| `src/main/resources/config/app.yaml` | Port, OCP payment routing, DIP repository choice and the EIP settings |
| `src/main/resources/dwl/` | DataWeave modules of the translation examples |
| `src/test/munit/solid/`, `src/test/munit/eip/` | MUnit suites, one per principle or pattern |
| `src/test/java/` | A test-only helper that creates a symbolic link for the file transfer suite, which Mule has no operation for |
| `docs/contracts/solid/` | RAML types of the LSP and ISP examples; documentation, not loaded by the app |
| `requests.http` | Sample requests |

The global error handler answers `APP:BAD_REQUEST` with 400, `APP:NOT_FOUND` with 404, `APP:CONFLICT` with 409, `APP:SERVICE_UNAVAILABLE` with 503, `APP:COMPENSATION_FAILED` and any other error with 500, as JSON.
The global error handler answers `APP:BAD_REQUEST` with 400, `APP:NOT_FOUND` with 404, `APP:CONFLICT` with 409, `APP:SERVICE_UNAVAILABLE` with 503, `APP:GATEWAY_TIMEOUT` with 504, `APP:COMPENSATION_FAILED` and any other error with 500, as JSON.

The file transfer example is the only one that uses the file system: its producer and consumer share an inbox directory (`eip.fileTransfer.*` in `app.yaml`; the inbox must exist at startup and defaults to the OS temporary directory). MUnit points the three directories under `target/` through system properties in [`pom.xml`](../pom.xml).

What each pattern example does is described in the [README](../README.md).

Expand Down
Loading