From 71eadfa9837ab1f244c85acb51df0eadbca135e2 Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Tue, 1 Dec 2026 17:41:46 +0000 Subject: [PATCH 1/3] feat: EIP wave 7, wire tap and file transfer examples (SW-276) --- AGENTS.md | 3 +- README.md | 25 +- docs/architecture.md | 5 +- pom.xml | 15 + requests.http | 73 +++ .../mule/eip/file-transfer/file-transfer.xml | 240 ++++++++++ src/main/mule/eip/wire-tap/wire-tap-audit.xml | 74 +++ src/main/mule/eip/wire-tap/wire-tap.xml | 133 ++++++ src/main/mule/global.xml | 13 +- src/main/resources/config/app.yaml | 13 + .../munit/eip/file-transfer-test-suite.xml | 424 ++++++++++++++++++ src/test/munit/eip/wire-tap-test-suite.xml | 335 ++++++++++++++ 12 files changed, 1346 insertions(+), 7 deletions(-) create mode 100644 src/main/mule/eip/file-transfer/file-transfer.xml create mode 100644 src/main/mule/eip/wire-tap/wire-tap-audit.xml create mode 100644 src/main/mule/eip/wire-tap/wire-tap.xml create mode 100644 src/test/munit/eip/file-transfer-test-suite.xml create mode 100644 src/test/munit/eip/wire-tap-test-suite.xml diff --git a/AGENTS.md b/AGENTS.md index e346753..b0119e4 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) 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. @@ -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. diff --git a/README.md b/README.md index d42bfef..c4013fb 100644 --- a/README.md +++ b/README.md @@ -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 218 cases at about 99.4%. ## SOLID in MuleSoft @@ -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:** @@ -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) 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 or timed-out copy, or one in memory when the app stops, is gone; 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, 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 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. 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`. @@ -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 lost copy, which 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. 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 gets 409; 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. @@ -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/ -before.xml @@ -238,7 +250,12 @@ 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 diff --git a/docs/architecture.md b/docs/architecture.md index 9fa7424..c59f75c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 ``` @@ -54,7 +55,9 @@ The open/closed example uses the same idea: `payment.flow.` in `app.yaml | `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). diff --git a/pom.xml b/pom.xml index 01eda30..cf88fa4 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,7 @@ 1.11.3 1.3.2 1.1.5 + 1.5.7 @@ -59,6 +60,13 @@ ${app.runtime} MULE_EE + + + ${project.build.directory}/munit-file-transfer/inbox + ${project.build.directory}/munit-file-transfer/processed + ${project.build.directory}/munit-file-transfer/error + http.port @@ -97,6 +105,13 @@ ${mule.aggregators.module.version} mule-plugin + + + org.mule.connectors + mule-file-connector + ${mule.file.connector.version} + mule-plugin + com.mulesoft.munit munit-runner diff --git a/requests.http b/requests.http index aec1d97..63ef7b1 100644 --- a/requests.http +++ b/requests.http @@ -360,3 +360,76 @@ POST {{base}}/eip/process-manager/replies Content-Type: application/json { "processId": "PM-replace-me", "step": "INVOICE", "outcome": "ISSUED" } + +### EIP wire tap — switch the simulated audit system off, then compare the inline write (503) with the tap (201) +PUT {{base}}/eip/wire-tap/audit/availability +Content-Type: application/json + +{ "available": false } + +### +POST {{base}}/eip/wire-tap/inline/orders +Content-Type: application/json + +{ "orderId": "ORD-7001", "amount": 120 } + +### +POST {{base}}/eip/wire-tap/orders +Content-Type: application/json + +{ "orderId": "ORD-7002", "amount": 120 } + +### +# Slow audit (3 s): the inline write waits, the tap answers at once +PUT {{base}}/eip/wire-tap/audit/availability +Content-Type: application/json + +{ "available": true, "delayMillis": 3000 } + +### +POST {{base}}/eip/wire-tap/inline/orders +Content-Type: application/json + +{ "orderId": "ORD-7003", "amount": 80 } + +### +POST {{base}}/eip/wire-tap/orders +Content-Type: application/json + +{ "orderId": "ORD-7004", "amount": 80 } + +### +# The copies received; the one lost while the audit system was off never arrives +GET {{base}}/eip/wire-tap/audit/copies + +### +PUT {{base}}/eip/wire-tap/audit/availability +Content-Type: application/json + +{ "available": true, "delayMillis": 0 } + +### +# The simulated audit system's own endpoint, called by both order flows +POST {{base}}/eip/wire-tap/audit/copies +Content-Type: application/json + +{ "orderId": "ORD-7005", "amount": 10 } + +### EIP file transfer — export a CSV file; the consumer reads it within about a second +POST {{base}}/eip/billing/exports +Content-Type: application/json + +{ "exportId": "EXP-7101", "orders": [ { "orderId": "ORD-7101", "customerId": "C-1", "amount": 120.5, "currency": "BRL" }, { "orderId": "ORD-7102", "customerId": "C-2", "amount": 80, "currency": "EUR" } ] } + +### +# A row without customerId and with a negative amount: the consumer rejects the whole file +POST {{base}}/eip/billing/exports +Content-Type: application/json + +{ "exportId": "EXP-7102", "orders": [ { "orderId": "ORD-7103", "amount": -5, "currency": "BRL" } ] } + +### +GET {{base}}/eip/billing/imports + +### +GET {{base}}/eip/billing/rejected-files diff --git a/src/main/mule/eip/file-transfer/file-transfer.xml b/src/main/mule/eip/file-transfer/file-transfer.xml new file mode 100644 index 0000000..7b3842e --- /dev/null +++ b/src/main/mule/eip/file-transfer/file-transfer.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + { + orderId: order.orderId, + customerId: order.customerId, + amount: order.amount, + currency: order.currency +}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 else false +--- +if (isEmpty(lines)) ["the file is empty"] +else if (lines[0] != header) ["the header must be $(header)"] +else if (isEmpty(rows)) ["the file has no rows"] +else flatten(rows map (row, index) -> rowViolations(row, index + 2))]]> + + + + + + + + + + + + + { + orderId: row.orderId, + customerId: row.customerId, + amount: row.amount as Number, + currency: row.currency +}]]> + + + + + + + + + + + + + + + file.rows map (row) -> row ++ { fileName: file.fileName, archivedAs: file.archivedAs, importedAt: file.importedAt })]]> + + + + + + + + + + + + diff --git a/src/main/mule/eip/wire-tap/wire-tap-audit.xml b/src/main/mule/eip/wire-tap/wire-tap-audit.xml new file mode 100644 index 0000000..ccaf39c --- /dev/null +++ b/src/main/mule/eip/wire-tap/wire-tap-audit.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/mule/eip/wire-tap/wire-tap.xml b/src/main/mule/eip/wire-tap/wire-tap.xml new file mode 100644 index 0000000..23e9508 --- /dev/null +++ b/src/main/mule/eip/wire-tap/wire-tap.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/mule/global.xml b/src/main/mule/global.xml index a03869f..c2a7973 100644 --- a/src/main/mule/global.xml +++ b/src/main/mule/global.xml @@ -16,7 +16,7 @@ - + @@ -58,6 +58,17 @@ output application/json + + + + + + + + diff --git a/src/main/resources/config/app.yaml b/src/main/resources/config/app.yaml index d635fa6..2aee72b 100644 --- a/src/main/resources/config/app.yaml +++ b/src/main/resources/config/app.yaml @@ -76,3 +76,16 @@ eip: processManager: paymentLimit: "1000" replyPath: "/eip/process-manager/replies" + # Wire tap: how long a call to the simulated audit system may take, inline or tapped, before it fails. + wireTap: + auditTimeoutMillis: "5000" + # File transfer: the directory the billing producer writes to (inbox) and where the consumer moves each file + # after reading it (processed or error). The inbox must exist when the application starts, so its default is + # the operating system's temporary directory itself; processed and error are created on the first move. So + # the app runs on any machine with no setup; a real integration uses a directory both applications can reach + # and that survives a restart. How often the consumer looks for new files. + fileTransfer: + inboxDirectory: "${java.io.tmpdir}" + processedDirectory: "${java.io.tmpdir}/mulesoft-patterns-examples/billing/processed" + errorDirectory: "${java.io.tmpdir}/mulesoft-patterns-examples/billing/error" + pollFrequencyMillis: "1000" diff --git a/src/test/munit/eip/file-transfer-test-suite.xml b/src/test/munit/eip/file-transfer-test-suite.xml new file mode 100644 index 0000000..d88832c --- /dev/null +++ b/src/test/munit/eip/file-transfer-test-suite.xml @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/munit/eip/wire-tap-test-suite.xml b/src/test/munit/eip/wire-tap-test-suite.xml new file mode 100644 index 0000000..a7c1dea --- /dev/null +++ b/src/test/munit/eip/wire-tap-test-suite.xml @@ -0,0 +1,335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 69ab33bbfbbe3ebdee30a39f8eda1db42bc6e24f Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Tue, 1 Dec 2026 18:03:48 +0000 Subject: [PATCH 2/3] fix: review round 1 on the wire tap and file transfer examples (SW-276) --- README.md | 10 +- requests.http | 2 +- .../mule/eip/file-transfer/file-transfer.xml | 75 +++++-- src/main/mule/eip/wire-tap/wire-tap.xml | 26 ++- src/main/resources/config/app.yaml | 6 +- .../munit/eip/file-transfer-test-suite.xml | 129 ++++++++++-- src/test/munit/eip/wire-tap-test-suite.xml | 183 ++++++++++++++++-- 7 files changed, 376 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index c4013fb..e537e63 100644 --- a/README.md +++ b/README.md @@ -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 218 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 225 cases at about 99.3%. ## SOLID in MuleSoft @@ -118,8 +118,8 @@ In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, | 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) 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 or timed-out copy, or one in memory when the app stops, is gone; 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, 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 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. 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` | +| 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, 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, 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: @@ -167,8 +167,8 @@ What the wave 6 suite shows, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go 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 lost copy, which 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. 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 gets 409; 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. +- 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; 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: diff --git a/requests.http b/requests.http index 63ef7b1..fcd8e0c 100644 --- a/requests.http +++ b/requests.http @@ -399,7 +399,7 @@ Content-Type: application/json { "orderId": "ORD-7004", "amount": 80 } ### -# The copies received; the one lost while the audit system was off never arrives +# The copies received; the one refused while the audit system was off never arrives GET {{base}}/eip/wire-tap/audit/copies ### diff --git a/src/main/mule/eip/file-transfer/file-transfer.xml b/src/main/mule/eip/file-transfer/file-transfer.xml index 7b3842e..18c14c1 100644 --- a/src/main/mule/eip/file-transfer/file-transfer.xml +++ b/src/main/mule/eip/file-transfer/file-transfer.xml @@ -19,7 +19,7 @@ directory, records the rows and moves the file away. POST /eip/billing/exports producer: writes mulesoft-patterns-billing-{exportId}.csv to the inbox, 202; 409 - while a file with that name is still in the inbox + while a file with that name is still in the inbox or being written (consumer: flow billing-import-export-file, started by the File connector's On New or Updated File source) GET /eip/billing/imports the rows the consumer recorded GET /eip/billing/rejected-files the files the consumer rejected, with the reason @@ -34,9 +34,13 @@ REPEATED FILE NAMES. The producer renames with overwrite="false": a second export with the same exportId is refused (409) while the first file is still in the inbox, and its temporary file is deleted. The connector - checks that the target exists and then moves (with REPLACE_EXISTING), which is not one atomic step, so the - producer flow runs one export at a time (maxConcurrency="1"); another writer outside this flow is not - covered. Once the consumer + checks that the target exists and then moves (with REPLACE_EXISTING), which is not one atomic step. So the + producer first claims the exportId in an object store (os:store failIfPresent) and releases it when the + publication ends: a concurrent request for the same exportId gets 409, requests for other ids run at the + same time. Not maxConcurrency="1" on the flow: an HTTP Listener under back-pressure answers 503 instead of + queuing (https://docs.mulesoft.com/mule-runtime/latest/execution-engine). A writer outside this application + is not covered by the claim. When the write or the rename fails the temporary file is deleted (best effort); + an application that stops mid-write leaves it, and the consumer never reads it. Once the consumer has moved the first file, the same name can arrive again: the consumer archives every file under a unique name ({name}.{uuid}.csv), so nothing in processed or error is overwritten. Without the unique name the move fails because the target exists, the file stays in the inbox and is read again on every poll (observed with @@ -54,8 +58,11 @@ name and no target directory yet, so the file was renamed inside the inbox and read again on every poll, its name one UUID longer each time. A file that always fails is retried forever, with an ERROR logged each time; a real integration limits the attempts (see eip/guaranteed-delivery). - The record is written under a key made of the file's name, modification time and size, so reading the same - file again (for example after the move failed) rewrites the same record instead of adding one. + The record is written under a key made of the file's name, modification time and the SHA-256 of its + content, so reading the same file again (for example after the move failed) rewrites the same record instead + of adding one. Deliveries that differ in content never share a record, however coarse the file system's + modification time; two byte-identical files of the same name with the same modification time cannot be told + apart and make one record (both are archived). NO WATERMARK (watermarkMode="DISABLED"): files leave the inbox once handled, so there is nothing to skip. A timestamp watermark picks only files newer than the last ones seen, and a renamed file keeps the @@ -73,18 +80,22 @@ DIRECTORIES (eip.fileTransfer.* in app.yaml). The inbox must exist when the application starts: the source fails to start when it does not ("Path '...' doesn't exist"), so its default is the operating system's temporary directory, which always exists, and the file name prefix mulesoft-patterns-billing- keeps the - consumer to this example's files. On a machine whose temporary directory is shared, any user can put a file - with that name there: point the inbox at a private directory outside a demo. processed and error are - created on the first move. + consumer to this example's files. processed and error default to folders under the same temporary directory + and are created on the first move. On a machine whose temporary directory is shared, none of the three is + private: another user can put a file with that name in the inbox, can create the processed or error folder + (or a link in its place) before the application does and so receive or redirect the archived files, and the + files may be readable by others. Outside a demo, point all three at directories only the application can + access. --> + - + @@ -109,16 +120,36 @@ payload.orders map (order) -> { }]]> + + + + + + + + + + + + + + + - + + + + + + @@ -128,6 +159,17 @@ payload.orders map (order) -> { + + + + + + + + + + + @@ -137,8 +179,17 @@ payload.orders map (order) -> { - + + + + + diff --git a/src/main/mule/eip/wire-tap/wire-tap.xml b/src/main/mule/eip/wire-tap/wire-tap.xml index 23e9508..8896cd4 100644 --- a/src/main/mule/eip/wire-tap/wire-tap.xml +++ b/src/main/mule/eip/wire-tap/wire-tap.xml @@ -16,7 +16,10 @@ received is copied to a (simulated) audit system. POST /eip/wire-tap/inline/orders before: the audit copy is written inline, in the main flow. Audit down - fails the order (503, 504 on a timeout); audit slow delays it. + (500, 502, 503 or no connection) fails the order with 503, a timeout (or a + 504 from the audit system) with 504; audit slow delays it. After a timeout + the order is not accepted, yet the audit system may still record a copy of + it (the simulator does). POST /eip/wire-tap/orders after: an Async scope with its own Try sends the copy. The order is accepted whether the audit system is up, slow or down. Simulated audit system (wire-tap-audit.xml): @@ -30,11 +33,14 @@ in the branch. The same documentation says the payload objects are not copied, only referenced: a processor that replaces the payload is safe, Java code that mutates a shared object inside the branch is not. - THE TAP IS LOSSY. The copy lives only in memory while the branch runs: if the audit system refuses it, if - the call times out, or if the application stops before the branch finishes, the copy is gone. This example - logs a WARN and does not retry. Use it only for copies you can afford to lose (monitoring, sampling, - debugging). An audit record that must not be lost needs to be persisted before the order is acknowledged and - delivered with retries: that is guaranteed delivery (eip/guaranteed-delivery), or a persistent queue. + THE TAP IS LOSSY, AND A FAILED CALL DOES NOT SAY WHAT HAPPENED. The copy lives only in memory while the + branch runs: if the audit system refuses it (switched off, 503) or the application stops before the branch + finishes, the copy is gone. If the call times out (eip.wireTap.auditTimeoutMillis) the outcome is unknown: + the audit system may still be working and record the copy later, and this simulator does. This example logs + a WARN ("not confirmed") and does not retry; a retry could record the copy twice. Use a wire tap only for + copies you can afford to lose (monitoring, sampling, debugging). An audit record that must not be lost needs + to be persisted before the order is acknowledged and delivered with retries to a receiver that tolerates + repeats: that is guaranteed delivery (eip/guaranteed-delivery), or a persistent queue. maxConcurrency is deliberately not set on the Async scope. The documentation says that at the maximum the scope "cannot receive additional requests" and points to the back-pressure page, which describes flow @@ -67,10 +73,10 @@ - + - + @@ -98,8 +104,8 @@ - - + + diff --git a/src/main/resources/config/app.yaml b/src/main/resources/config/app.yaml index 2aee72b..2ab8ec7 100644 --- a/src/main/resources/config/app.yaml +++ b/src/main/resources/config/app.yaml @@ -82,10 +82,12 @@ eip: # File transfer: the directory the billing producer writes to (inbox) and where the consumer moves each file # after reading it (processed or error). The inbox must exist when the application starts, so its default is # the operating system's temporary directory itself; processed and error are created on the first move. So - # the app runs on any machine with no setup; a real integration uses a directory both applications can reach - # and that survives a restart. How often the consumer looks for new files. + # the app runs on any machine with no setup. Where the temporary directory is shared, none of the three is + # private to the application: point all three at private directories outside a demo. A real integration uses + # directories both applications can reach and that survive a restart. fileTransfer: inboxDirectory: "${java.io.tmpdir}" processedDirectory: "${java.io.tmpdir}/mulesoft-patterns-examples/billing/processed" errorDirectory: "${java.io.tmpdir}/mulesoft-patterns-examples/billing/error" + # How often the consumer looks for new files. pollFrequencyMillis: "1000" diff --git a/src/test/munit/eip/file-transfer-test-suite.xml b/src/test/munit/eip/file-transfer-test-suite.xml index d88832c..ca9b6ce 100644 --- a/src/test/munit/eip/file-transfer-test-suite.xml +++ b/src/test/munit/eip/file-transfer-test-suite.xml @@ -16,24 +16,29 @@ - + + - + + - + @@ -43,8 +48,17 @@ + + + + + + + + + @@ -241,8 +255,10 @@ + + @@ -298,10 +314,10 @@ { name: 'SHORT', content: 'orderId,customerId,amount,currency\nORD-1,C-1\n' }, { name: 'QUOTE', content: 'orderId,customerId,amount,currency\n"ORD-1,C-1,10,BRL\n' } ]]"> - + - + @@ -341,12 +357,23 @@ + + + + + + + + + + - + + @@ -356,6 +383,7 @@ + @@ -363,7 +391,7 @@ - + @@ -387,10 +415,87 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/munit/eip/wire-tap-test-suite.xml b/src/test/munit/eip/wire-tap-test-suite.xml index a7c1dea..dfc9cb3 100644 --- a/src/test/munit/eip/wire-tap-test-suite.xml +++ b/src/test/munit/eip/wire-tap-test-suite.xml @@ -146,7 +146,7 @@ - + @@ -154,12 +154,12 @@ - + - + - + @@ -175,7 +175,7 @@ - + @@ -187,7 +187,7 @@ - + @@ -223,17 +223,14 @@ - - - @@ -258,7 +255,7 @@ - + @@ -268,7 +265,10 @@ - + + + + @@ -276,7 +276,7 @@ - + @@ -286,6 +286,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -327,9 +477,16 @@ + + + + + + - + + From 3f4e5a7c1eb63f289974a8c64b76ac165b298e5a Mon Sep 17 00:00:00 2001 From: brunosouzas-agent Date: Tue, 1 Dec 2026 18:26:28 +0000 Subject: [PATCH 3/3] fix: review round 2 on the file transfer and wire tap examples (SW-276) --- README.md | 7 +- docs/architecture.md | 1 + .../mule/eip/file-transfer/file-transfer.xml | 40 +++++---- src/main/mule/global.xml | 4 +- src/main/resources/config/app.yaml | 5 +- .../examples/test/SymbolicLinks.java | 16 ++++ .../munit/eip/file-transfer-test-suite.xml | 87 +++++++++++++++++-- src/test/munit/eip/wire-tap-test-suite.xml | 25 ++++++ 8 files changed, 158 insertions(+), 27 deletions(-) create mode 100644 src/test/java/com/brunosouzas/examples/test/SymbolicLinks.java diff --git a/README.md b/README.md index e537e63..5738d11 100644 --- a/README.md +++ b/README.md @@ -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 225 cases at about 99.3%. +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 @@ -119,7 +119,7 @@ In progress. Patterns from Hohpe and Woolf's *Enterprise Integration Patterns*, | 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, 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, 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` | +| 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: @@ -168,7 +168,7 @@ What the wave 6 suite shows, observed on Mule 4.9.17 with MUnit 3.7.1 (calls go 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; 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. +- 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: @@ -259,6 +259,7 @@ src/main/resources/config/app.yaml port, OCP payment routing, DIP repository c 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/-test-suite.xml eip/-test-suite.xml diff --git a/docs/architecture.md b/docs/architecture.md index c59f75c..43dfa2c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -52,6 +52,7 @@ The open/closed example uses the same idea: `payment.flow.` 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 | diff --git a/src/main/mule/eip/file-transfer/file-transfer.xml b/src/main/mule/eip/file-transfer/file-transfer.xml index 18c14c1..fecf466 100644 --- a/src/main/mule/eip/file-transfer/file-transfer.xml +++ b/src/main/mule/eip/file-transfer/file-transfer.xml @@ -77,15 +77,27 @@ https://docs.mulesoft.com/runtime-manager/developing-applications-for-cloudhub). There, use SFTP, an object storage service or a shared server; this example uses the local disk only to run with no external system. + WHAT COUNTS AS INVALID is what sf-check-billing-file checks. The DataWeave CSV reader is lenient: text after + a closing quote is dropped with a warning and the row can still pass (observed), so a real contract needs a + stricter check of the raw file. A failure of the check itself is a processing failure (the file stays). + DIRECTORIES (eip.fileTransfer.* in app.yaml). The inbox must exist when the application starts: the source fails to start when it does not ("Path '...' doesn't exist"), so its default is the operating system's temporary directory, which always exists, and the file name prefix mulesoft-patterns-billing- keeps the - consumer to this example's files. processed and error default to folders under the same temporary directory + consumer to this example's files. The matcher takes regular files only and excludes directories and symbolic + links (regularFiles="REQUIRE", directories="EXCLUDE", symLinks="EXCLUDE", each REQUIRE, INCLUDE or EXCLUDE, + INCLUDE by default: https://docs.mulesoft.com/file-connector/latest/file-documentation). symLinks is needed: + File connector 1.5.7 reports a link to a file as a regular file too (observed). It judges the entry when it + lists the directory, so it covers neither hard links nor a file replaced by a link after the listing. + processed and error default to folders under the same temporary directory and are created on the first move. On a machine whose temporary directory is shared, none of the three is private: another user can put a file with that name in the inbox, can create the processed or error folder (or a link in its place) before the application does and so receive or redirect the archived files, and the - files may be readable by others. Outside a demo, point all three at directories only the application can - access. + files may be readable by others. A shared temporary directory with the sticky bit (/tmp on Linux) adds two + consequences for the inbox: another user's regular file (or a hard link, where the system allows it) with a + matching name is read like the application's own, so its rows are recorded; and a file the application + cannot move or delete, because another user owns it, is read again on every poll for as long as the + application runs. Outside a demo, point all three at directories only the application can access. --> @@ -103,6 +115,9 @@ + + + @@ -175,7 +190,7 @@ payload.orders map (order) -> { - + @@ -215,10 +230,9 @@ attributes.fileName ++ "@" ++ (attributes.lastModifiedTime as String) ++ ":" ++ - - - - + + rowViolations(row, index + 2))]]> - - - - - - - - + + diff --git a/src/main/mule/global.xml b/src/main/mule/global.xml index c2a7973..3fc9350 100644 --- a/src/main/mule/global.xml +++ b/src/main/mule/global.xml @@ -62,8 +62,8 @@ output application/json - - + + - + @@ -68,7 +68,7 @@ - + @@ -77,7 +77,7 @@ - + @@ -87,7 +87,7 @@ - + @@ -335,7 +335,7 @@ - + @@ -499,6 +499,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/munit/eip/wire-tap-test-suite.xml b/src/test/munit/eip/wire-tap-test-suite.xml index dfc9cb3..3560ab7 100644 --- a/src/test/munit/eip/wire-tap-test-suite.xml +++ b/src/test/munit/eip/wire-tap-test-suite.xml @@ -466,6 +466,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + +