Integration patterns in Mule: catalog
- 7 min read
On this page
Code
This page maps each pattern from the book Enterprise Integration Patterns (Hohpe and Woolf) to the Mule 4 component or feature that implements it. It also points to the page in the series that explains the pattern with an example that runs. The reason for the series is in the article Integration patterns in Mule: you already use them, you just don’t know their names.
The sections follow the book’s groups. The question in each row sums up the pattern’s problem, based on the pattern’s page on the book’s site.
Channels: where the message travels
| Pattern | Question it answers | In Mule | Page |
|---|---|---|---|
| How do you make sure a single receiver consumes each message? | Anypoint MQ queue, on the broker. VM Connector queues also deliver each message to a single consumer, but they live inside the Mule runtime and do not replace a broker | Coming soon | |
| How do you deliver the same event to every interested party? | Anypoint MQ message exchange (the broker resource, not the Anypoint Exchange where assets live), which, with no routing rules on its bindings, copies each message to every queue bound to it | Publish-subscribe | |
| What do you do with a message that cannot be delivered? | Anypoint MQ dead letter queue: after a number of delivery attempts without acknowledgment (10 by default), the broker moves the message to the queue’s DLQ | Dead letter channel | |
| What do you do with a message that arrives but makes no sense to the receiver? | No dedicated component; error handling that sends the message to a queue separate from the DLQ, because retrying will not fix it | Coming soon | |
| How do you avoid losing the message if the messaging system goes down? | Anypoint MQ queues; persistent VM queues, which are not available on CloudHub 2.0 or Runtime Fabric; the reliability pattern in the Mule documentation | Coming soon | |
| How do you connect an application to the messaging system? | The role connectors play (Database, Salesforce, SFTP…) | Coming soon |
Message construction: what the message carries
| Pattern | Question it answers | In Mule | Page |
|---|---|---|---|
| How do you get a reply when applications communicate through messages? | HTTP Request; the VM Publish Consume operation | Coming soon | |
| How does the replier know where to send the reply? | The temporary reply queue that VM Publish Consume creates and discards on its own | Coming soon | |
| How do you know which request a reply belongs to? | An ID carried in the request and returned in the reply. Mule’s correlationId plays a similar role between applications: HTTP Request sends it in the X-CORRELATION-ID header, the called application’s listener adopts it, and the logs of both show the same ID |
Correlation identifier | |
| How do you indicate that a message has gone stale and should no longer be processed? | The time to live (TTL) of the Anypoint MQ queue, at most two weeks | Coming soon |
Routing: where the message goes
| Pattern | Question it answers | In Mule | Page |
|---|---|---|---|
| How do you send each message to the right destination based on its content? | Choice | Coming soon | |
| How do you discard the messages you are not interested in? | A Choice in which only the route for accepted messages does any processing. Choice does not end the flow: whatever comes after it runs for every message, including the discarded ones | Coming soon | |
| How do you process a message that carries several items? | For Each, Parallel For Each | Coming soon | |
| How do you combine related messages into one? | The Aggregators module, with size-based, time-based and group-based aggregators; the aggregation step in Scatter-Gather | Coming soon | |
| How do you send to several destinations and combine the replies? | Scatter-Gather. If a route fails, it throws MULE:COMPOSITE_ROUTING with the errors and the results of the routes that succeeded |
Coming soon | |
| How do you route a message through several steps when they may not be known in advance and may not be sequential? | No dedicated component. A flow that keeps the process state (in an object store or a database, when the process spans more than one execution) and decides the next step from the intermediate results | Coming soon |
Transformation: what changes in the content
| Pattern | Question it answers | In Mule | Page |
|---|---|---|---|
| How do systems with different formats exchange data? | Transform Message (DataWeave) | Coming soon | |
| How do you handle a large message when only a few fields matter? | Transform Message selecting or removing fields. Message Filter discards the whole message; Content Filter trims its content | Coming soon | |
| How do you reduce dependencies between applications that use different formats? | No component; a common model shared by the APIs | Coming soon | |
| How do you complete a message that does not carry all the data? | An operation’s target variable stores the fetched data without overwriting the payload; a DataWeave script combines the two | Coming soon | |
| How do you reduce the amount of data that travels in the message without losing information? | No component; Object Store or external storage, with only the key traveling in the message | Coming soon |
Endpoints: how the application receives and consumes
| Pattern | Question it answers | In Mule | Page |
|---|---|---|---|
| How do you consume messages as soon as they arrive? | Event sources: HTTP Listener, VM Listener, Anypoint MQ Subscriber | Coming soon | |
| How do you consume a message when the application is ready for it? | A Scheduler followed by a read; the Consume operation of VM and Anypoint MQ | Coming soon | |
| How do you process several messages from the same queue at the same time? | The concurrent consumers of the VM listener (4 by default), or several replicas on the same queue | Coming soon | |
| How do you receive the same message twice without doubling the effect? | Idempotent Message Validator, with a business key in idExpression |
Idempotent receiver | |
| How do you control the transaction with the messaging system? | Transactions started at the event source or in a Try | Coming soon |
Where the “In Mule” column says “no dedicated component”, the pattern still applies, but you build it yourself out of flows, configuration and a design decision.
The example that goes with the series
The scenario is always the same: an order that goes through payment, inventory and invoicing. The patterns that run inside Mule have a runnable example in the mulesoft-patterns-examples repository, under src/main/mule/eip/<pattern>/, each with its own MUnit suite and no external systems. The ones that depend on Anypoint MQ, such as the message exchange and the DLQ, are explained on their page with the broker configuration, based on the documentation, because they do not run without it.
git clone https://github.com/brunosouzas/mulesoft-patterns-examples.git
cd mulesoft-patterns-examples
mvn clean test
MUnit runs on the Enterprise runtime, so Maven needs access to the MuleSoft Enterprise repository (credentials in ~/.m2/settings.xml).