Studio Visual Editor
-
Add a Resequencer Flow Control before the aggregator
The Resequencer waits for all of the messages in the group to arrive (keeping track of MULE_CORRELATION_ID and MULE_CORRELATION_GROUP_SIZE) and then reorders them according to their MULE_CORRELATION_SEQUENCE index.
The Resequencer outputs three distinct messages, so the Aggregator is still needed to merge them into one.
-
Run the Mule project.
-
Send the HTTP connector 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>
With the Resequencer in place, messages now reach the aggregator in the correct order and are assembled accordingly.
To really take advantage of splitting the message, you should deploy your app to a cluster of servers. By following the steps below, you can simulate the random delays of a cluster of servers.
|
The following is not an implementable solution but rather a proof of concept that highlights what occurs in the flow.
|
-
Add a Groovy component in the second flow, between the VM and the logger.
-
Copy the following code into the Groovy Component:
random = new Random()
randomInt = random.nextInt(10)*1000
Thread.sleep(randomInt)
return payload
This snippet of code simply introduces a random delay of up to 10 seconds. As each message is running asynchronously, this delay can potentially alter the order in which messages move on to the next step, simulating what could happen in a real implementation with parallel servers processing each fraction of the message.
-
Run the project.
-
Send the HTTP connector 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 now see three messages logged into the console, one for every "actor" XML element. These will likely not have their MULE_CORRELATION_SEQUENCE indexes in order due to the random delays caused by the Groovy code.
Below these, you will see a fourth longer message where these indexes are put back in order by the Resequencer.
XML Editor
-
Add a Resequencer Flow Control before the aggregator.
<resequencer failOnTimeout="true" doc:name="Resequencer"/>
The Resequencer waits for all of the messages in the group to arrive (keeping track of MULE_CORRELATION_ID and MULE_CORRELATION_GROUP_SIZE) and then reorders them according to their MULE_CORRELATION_SEQUENCE index.
The Resequencer outputs three distinct messages, so the Aggregator is still needed to merge them into one.
-
Run the Mule project.
-
Send the HTTP connector 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>
With the Resequencer in place, messages now reach the aggregator in the correct order and are assembled accordingly.
To really take advantage of splitting the message, you should deploy your app to a cluster of servers. By following the steps below, you can simulate the random delays of a cluster of servers.
|
The following is not an implementable solution but rather a proof of concept that highlights what occurs in the flow.
|
-
Add a Groovy component in the second flow, between the VM and the first logger.
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy">
<![CDATA[
random = new Random()
randomInt = random.nextInt(10)*1000
Thread.sleep(randomInt)
return payload
]]>
</scripting:script>
</scripting:component>
This snippet of code simply introduces a random delay of up to 10 seconds. As each message is running asynchronously, this delay can potentially alter the order in which messages move on to the next step, simulating what could happen in a real implementation with parallel servers processing each fraction of the message.
-
Run the project.
-
Send the HTTP connector 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 now see three messages logged into the console, one for every "actor" XML element. These will likely not have their MULE_CORRELATION_SEQUENCE indexes in order due to the random delays caused by the Groovy code.
Below these, you should see a fourth longer message where these indexes are in order by the Resequencer.