Studio Visual Editor
-
Drag a VM endpoint to the end of the flow.
-
Drag a second VM endpoint outside the existing flow, below it. This will create a new flow.
-
Drag the existing logger you had in the first flow to the new second flow, after the VM endpoint.
-
Configure the two VM endpoints. Change both their Queue Path to step2
.
Once both VMs have the same Queue Path configured, they will be linked. Messages that arrive to the first VM will continue their path out of the second VM. What you have at this point appears to work identically to what you built in the first example. There is, however, one key difference: each fraction of the message will be processed simultaneously rather than in sequence. If you deploy your app to a cluster of servers this will have a big effect on performance.
-
Make the initial HTTP endpoint one-way, as there are no useful messages being returned
-
Add a Collection aggregator in the second flow, after the Logger.
-
Add one more logger after the Collection aggregator, to see how the final message is output.
-
Run the Mule project.
-
You must now send the HTTP endpoint an HTTP request that includes a body with an attached XML file.
Send a Post request to http://localhost:8081/ attaching XML to the body of the message. Sample XML is provided below.
|
The easiest way to do this is sending posts via a browser extension such as Postman (for Google Chrome) or the curl command line utility.
|
<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<actors>
<actor id="1">Christian Bale</actor>
<actor id="2">Liam Neeson</actor>
<actor id="3">Will Ferrell</actor>
</actors>
<foo:singers>
<foo:singer id="4">Dave Grohl</foo:singer>
<foo:singer id="5">B.B. King</foo:singer>
<foo:singer id="6">Weird Al</foo:singer>
</foo:singers>
</root>
You should see four messages logged into the console: the first three should be short, one for every "actor" XML element (notice the ID attribute in each message). After these first three messages there should be a fourth, longer message, which is logged after the aggregator has run. Notice two things:
-
Although the aggregator was triggered three times, once for every fraction of the message that reached it, it produced one single output message, only when all of the fractions were in place
-
The aggregator assembles the message in the order in which fractions have arrived; the final message may be shuffled. If maintaining the original sequence is important to you, take a look at the Advanced Example 2 in this page
XML Editor
-
Add a second flow to your project.
<flow name="splitterFlow1" doc:name="splitterFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8082" doc:name="HTTP"/>
<splitter expression="#[xpath('//actor')]" doc:name="Splitter"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
<flow name="splitterFlow2" doc:name="splitterFlow2">
</flow>
-
Remove the logger in the first flow, add an identical one inside the second flow.
<flow name="splitterFlow1" doc:name="splitterFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8082" doc:name="HTTP"/>
<splitter expression="#[xpath('//actor')]" doc:name="Splitter"/>
</flow>
<flow name="splitterFlow2" doc:name="splitterFlow2">
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
-
Link both flows through a couple of VM endpoints, an outbound endpoint in the first flow and an inbound endpoint in the second flow.
<flow name="splitterFlow1" doc:name="splitterFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8082" doc:name="HTTP"/>
<splitter expression="#[xpath('//actor')]" doc:name="Splitter"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="step2" doc:name="VM"/>
</flow>
<flow name="splitterFlow2" doc:name="splitterFlow2">
<vm:inbound-endpoint exchange-pattern="one-way" path="step2" doc:name="VM"/>
</flow>
Provide these same attributes for both VM endpoints:
Attribute |
Value |
exchange-pattern
|
one-way
|
path
|
step2
|
doc:name
|
VM
|
Once both VMs share the same Queue Path, they will be linked. Messages that arrive to the first VM will continue their path out of the second VM. What you have at this point appears to work identically to what you built in the first example. There is, however, one key difference: each fraction of the message will be processed simultaneously rather than in sequence. If you deploy your app to a cluster of servers this will have a big effect on performance.
-
Add a Collection aggregator in the second flow, after the logger.
<collection-aggregator failOnTimeout="false" doc:name="Collection Aggregator"/>
Attribute |
Value |
failOnTimeout
|
true
|
doc:name
|
Collection Aggregator
|
-
Run the Mule project.
-
You must now send the HTTP endpoint an HTTP request that includes a body with an attached XML file. Send a Post request to http://localhost:8081/ attaching XML to the body of the message. Sample XML is provided below.
|
The easiest way to do this is sending posts via a browser extension such as Postman (for Google Chrome), or using the curl command-line utility.
|
<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<actors>
<actor id="1">Christian Bale</actor>
<actor id="2">Liam Neeson</actor>
<actor id="3">Will Ferrell</actor>
</actors>
<foo:singers>
<foo:singer id="4">Dave Grohl</foo:singer>
<foo:singer id="5">B.B. King</foo:singer>
<foo:singer id="6">Weird Al</foo:singer>
</foo:singers>
</root>
You should see four messages logged into the console: the first three should be short, one for every "actor" XML element (notice the ID attribute in each message). After these first three messages there should be a fourth, longer message, which is logged after the aggregator has run. Notice two things:
-
Although the aggregator was triggered three times, once for every fraction of the message that reached it, it produced one single output message, only when all of the fractions were in place
-
The aggregator assembles the message in the order in which fractions have arrived; the final message may be shuffled. If maintaining the original sequence is important to you, take a look at the Advanced Example 2 in this page