I described in my previous blog about parallel processing, in this blog also I am continuing my previous blog but adding new flavor of parallel processing in Mulesoft.
Splitter flow control splits a message into separate fragments and then sends these fragments parallel and concurrent to the next message processor in the flow. Segments are identified based on an expression parameter, usually written in Mule Expression Language (MEL), but other formats can be employed also. There are three ways we can spilt Mulesoft message.
Splitter — Splitter can split all types of data like Object, XML, JSON, and Payload based on MEL (Mule expression language) and processes each split into individual thread. .
Collection Splitter – If input type is collection, then collection splitter split data based on collection and process each element in individual thread.
Chunk Splitter – Chunk of splitter spilts message into chunk of bytes based on user input and processes each chunk of bytes in individual thread.
Since Collection splitter is one of the most usable splitter in Mulesoft. So I am showing example about Collection splitter.
In this example HasMap is coming as payload. Collection Splitter splits HasMap into different threads (limiting max 50 threads) and processes these threads in parallel.
Flow diagrame to implement parallel processing through Mulesoft Collection Splitter
Mulesoft code for parallel processing (Splitter)
<flow name="Vanrish-processFlow" processingStrategy="allow50Threads">
<logger message="*** Starting Vanrish-processFlow ***" category="edi-vanrish-process" level="INFO" doc:name="Flow Start Log"/>
<set-payload value="#[map-payload:processing]" doc:name="Payload Processing"/>
<set-variable variableName="numberOfMessages" value="#[payload.entrySet().size()]" doc:name="Variable"/>
<logger message="Processing #[flowVars['numberOfMessages']] entities" level="INFO" doc:name="logger-status go to database"/>
<splitter doc:name="Collection Splitter" expression="#[payload.entrySet()]"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="VanrishVM" doc:name="VM"/>
<logger message="*** Ending Vanrish-processFlow ***" category="edi-Vanrish-process" level="INFO" doc:name="Flow End Log"/>
</flow>
<flow name="Vanrish_Splitter_Demo" processingStrategy="allow50Threads">
<vm:inbound-endpoint exchange-pattern="one-way" path="VanrishVM" doc:name="VM"/>
<logger message="Company Canonical Start Time -> #[server.dateTime]" level="INFO" doc:name="Company Logger"/>
<flow-ref name="vanrishMsgPrivateFlow" doc:name="companyMsgPrivateFlow"/>
</flow>
Java Profiler is to show how Mulesoft Splitter splits collection message into multiple threads and process data

Rajnish Kumar, the CTO of Vanrish Technology, brings over 25 years of experience across various industries and technologies. He has been recognized with the “AI Advocate and MuleSoft Community Influencer Award” from the Salesforce/MuleSoft Community, showcasing his dedication to advancing technology. Rajnish is actively involved as a MuleSoft Mentor/Meetup leader, demonstrating his commitment to sharing knowledge and fostering growth in the tech community.
His passion for innovation shines through in his work, particularly in cutting-edge areas such as APIs, the Internet Of Things (IOT), Artificial Intelligence (AI) ecosystem, and Cybersecurity. Rajnish actively engages with audiences on platforms like Salesforce Dreamforce, World Tour, Podcasts, and other avenues, where he shares his insights and expertise to assist customers on their digital transformation journey.