These slides will describe the developer, How to use the collection splitter and aggregator and the things which we need to consider while using the Collection Splitter and Aggregator.
Human Factors of XR: Using Human Factors to Design XR Systems
Collection Splitter Aggregator in Mule ESB
1. Collection Splitter-Aggregator in Mule ESB
Introduction:
CollectionSplitter- Asthe name says,it will splitsthe messageintoindividual messages.Eachindividual
message contains3 correlationproperties.
a. Mule correlationgroupsize – Whichis nothingbutthe payloadsize.
b. Mule correlationsequence–sequence numberof amessage.
c. Mule correlationId – Whichisthe unique idforthe entire group.Eachindividual message inthe
groupwill containthisid.
CollectionAggregator- Itwill aggregate the individualmessagesintocollection.The aggregationlogic
wouldhappenbasedonthe correlationdetails.
Let ushave a lookat the configurationof CollectionSplitter:
Enable Correlation: Thisfiledhas3 options.
a. IF_NOT_SET – This isthe default option.Itwill maintainthe existingcorrelationdetails.
b. ALWAYS– It will overridethe existingcorrelationdetails.
c. NEVER– No Actiononthe message properties.
Message InfoMapping:Thisfieldisusedtocreate a customcorrelationandmessage ids.It’soptional
Let ushave a lookat the configurationof CollectionAggregator:
2. Fail On Timeout–This fieldacceptsvaluesastrue/false.Defaultistrue.
If the value istrue thiscomponentwill throw the response timeoutexceptionafterthe specified
timeout.
If the value isfalse thenthe componentwill aggregate the incomplete results.
Timeout– Specifytime inmilliseconds.
Store Prefix –This isoptional.If the value isemptythenmule will create aunique store name forus.
How to Use:
1. Simple collectionsplitter-aggregator.
In the above flowdiagram,Splittercomponentwill splitthe booksobjectintoindividual
message andprocesseachbookobjectto nextmessage processor,the Aggregatorcomponent
will aggregate the updatedbooksprice object.The outcome of the Aggregatorcomponentwill
be the collectiontype.
Whenevermessagecomestosplittercomponent,itwillsplitthe messageandassignthe
correlationdetailstoeachobject/individual message.Aggregatorwill aggregate the results
basedon the correlationdetails.
Here,Mule will take of creatingcorrelationdetails.
3. 2. Multiple Collectionsplitter-aggregatorsinthe same flowor in the subsequentsub flows.
Well,if we wantto use multiple splitter-aggregatorsinthe flow.The configurationwill be looks
like
If we runthis flow,thenwe wouldgetanunexpectedresult.Inthiscase,Mule will not
aggregate the resultscorrectly.
Let ussee why,
At the time of applicationstartup,mule will create alistable objectstore foreachcollection
aggregatorcomponentbasedonthe store prefix name.If we don’tprovide the store-prefix
name inthe configuration,Mule will create aunique store prefix name forus.The construction
of store-prefixlogicisdependsuponthe mule context, flow constructname andclassname of
the aggregator.
In the above flowdiagram,these twosplitter-aggregatorsare beingcalledfromthe same flow
(books-students-splitter-aggregator-flow),sothe flow constructname forthe bothof these
componentswill be same.Inthisscenario,Mule will create the same store name forbothof the
aggregatorcomponents.
Whenthe message comestoaggregator component, itwill checkthe correlationgroupalready
processedbythe correlationid(isthe objectstore containsthe correlationid).Inthe above
diagram,the firstaggregatorcomponent(bookaggregatorcomponent) wouldgive false butthe
secondaggregatorcomponent(studentaggregatorcomponent) wouldgivetrue because the
store namesare same.
4. i. If it returnsfalse,thenthe componentwill aggregate the resultsandaddthe
correlationidtothe store.
ii. If it returnstrue thenit will notaggregate the results.The message will be
movedtothe nextmessage processor.
That’s why,it’salwaysbettertogive the unique store prefix name forthe aggregator
componentasshownbelow.
3. Multiple CollectionSplitter-aggregatorsinforeachloop.
We can add ‘n’numberof aggregatorsby givingunique name tostore prefix.Whatwill happen,
if we use collectionaggregatorwithinfor-eachscope?
Whenthe message comesintofor-eachscope,itwill create correlationid,correlationsequence
and correlationgroupsize.For eachmessage,the correlationidwill be same.
Whenthe message comestocollectionaggregator,itwill checkwhetherthe groupisalready
processedforthe correlationid.If the groupisalreadyprocessedwiththe correlationidthen
the componentwill notaggregate the results.Sowe will notgetthe aggregatedresultsfromthe
2nd
message onwards.
To overcome thissituation,we have tomaintainunique correlationidforeachmessage inthe
for-loop.
Let ushave a lookat the belowconfiguration
5. In above diagram,the veryfirstcomponentinfor-eachscope isagroovyscript component
whichisusedto generate aunique correlationidasshownbelow.
By addingthe above linesin foreachscope,we can maintainthe unique correlationidforeach
message.
Finally,we gotthe aggregatedresultsbymaintainingthe correctcorrelationdetails.
Conclusion:
6. While usingthe Mule collectionsplitter-aggregator,we needtoconsiderthe below points.
1. We shoulduse the unique store prefix name.
2. We shouldmaintainthe uniquecorrelationidinforeachscope.
References:
http://forums.mulesoft.com/questions/25294/mule-collection-aggregator-is-unable-to-aggregate-
results-based-on-the-correlation_BAD.html
https://docs.mulesoft.com/mule-user-guide/v/3.7/splitter-flow-control-reference
Thank you