Studio Visual Editor
-
Drag a VM connector to the end of the flow.
-
Drag a second VM connector outside the existing flow, below it. This creates a new flow.
-
Drag the existing aggregator and logger you had in the first flow to the new second flow, after the VM connector.
-
Configure the two VM connectors. Change both their Queue Path to
step2
.After you configure both VMs with the same Queue Path, they are linked. Messages that arrive to the first VM 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 is processed simultaneously rather than in sequence. If you deploy your app to a cluster of servers, this has a big effect on performance.
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="SplitterExampleFlow1" > <file:inbound-endpoint path="./src/main/resources/" connector-ref="File" pollingFrequency="5000" responseTimeout="10000" doc:name="File"> <file:filename-regex-filter pattern="vip.xml" caseSensitive="true"/> </file:inbound-endpoint> <splitter expression="#[xpath3('//*:actor/text()',payload,'NODESET')]" doc:name="Splitter"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> </flow> <flow name="xpathFlow"> </flow>
-
Move both loggers and the Collection Aggregator to the second flow and connect them and link both flows through a couple of VM connectors, an outbound connector in the first flow and an inbound connector in the second flow.
<flow name="SplitterExampleFlow1" > <file:inbound-endpoint path="./src/main/resources/" connector-ref="File" pollingFrequency="5000" responseTimeout="10000" doc:name="File"> <file:filename-regex-filter pattern="vip.xml" caseSensitive="true"/> </file:inbound-endpoint> <splitter expression="#[xpath3('//*:actor/text()',payload,'NODESET')]" doc:name="Splitter"/> <vm:outbound-endpoint exchange-pattern="one-way" path="step2" connector-ref="VM" doc:name="VM"/> </flow> <flow name="xpathFlow"> <vm:inbound-endpoint exchange-pattern="one-way" path="step2" connector-ref="VM" doc:name="VM"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/> <logger message="#[payload]" level="INFO" doc:name="Logger"/> </flow>
Provide these same attributes for both VM connectors:
Attribute Value exchange-pattern
one-way
After both VMs share the same Queue Path, they are linked. Messages that arrive to the first VM 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 processes simultaneously rather than in sequence. If you deploy your app to a cluster of servers this has a big effect on performance.
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.