There is always a bottleneck of application when application is being read or written to multiple sources. Application always takes more time to process.
Parallel processing techniques can help reduce the time it takes to process a solution and make application fast.
So what is parallel processing?
Parallel processing is a form of process in which many process are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved at the same time
Mule introduces Scatter-Gather processor to implement parallel processing. <All> message processor replaced by scatter-Gather in Mule 3.5 version with more feature. Scatter-Gather router sends a message for concurrent processing to all configured routes. It uses a thread pool to concurrently execute all routes. This means that the total time the caller thread needs to be waiting for routes to respond is no longer the sum of all route’s time, but just the longest of them. If there are no failures, Mule aggregates the results from each of the routes into a message collection. If any exception comes during Scatter-Gather process it throws a CompositeRoutingException, which maps each exception to its corresponding route.
Flow diagrame to implement parallel processing for mule application
Mule code for parallel processing (scatter-Gather)
<custom-transformer class="com.vanrish.transformer.GenerateMessageTransformer" doc:name="Java Transformer"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<expression-filter expression="#[flowVars.COM != null]" doc:name="Expression Filter"/>
<set-payload value="#[flowVars.COM]" doc:name="Set Payload"/>
<logger message="Msg => #[payload.message]" level="DEBUG" doc:name="Msg Log"/>
<custom-transformer class="com. vanrish.transformer.ComTransformer" doc:name="Java Transformer"/>
</processor-chain>
<processor-chain>
<expression-filter expression="#[flowVars.CON != null]" doc:name="CON Expression Filter"/>
<set-payload value="#[flowVars.CON]" doc:name="Set Payload"/>
<logger message="Msg => #[payload.message]" level="DEBUG" doc:name="Msg Log"/>
<custom-transformer class="com.vanrish. transformer.ConTransformer" doc:name="Java Transformer"/>
</processor-chain>
<processor-chain>
<expression-filter expression="#[flowVars.CBA != null]" doc:name="CBA Expression Filter"/>
<set-payload value="#[flowVars.CBA]" doc:name="Set Payload"/>
<logger message="Msg => #[payload.message]" level="DEBUG" doc:name="Msg Log"/>
<custom-transformer class="com. vanrish.transformer.CbaTransformer" doc:name="Java Transformer"/>
</processor-chain>
<processor-chain>
<expression-filter expression="#[flowVars.IDF != null]" doc:name="IDF Expression Filter"/>
<set-payload value="#[flowVars.IDF]" doc:name="Set Payload"/>
<logger message="IDF => #[payload.message]" level="DEBUG" doc:name="Msg Log"/>
<custom-transformer class="com. vanrish.transformer.IdfTransformer" doc:name="Java Transformer"/>
</processor-chain>
<processor-chain>
<expression-filter expression="#[flowVars.CCI != null]" doc:name="Expression Filter"/>
<set-payload value="#[flowVars.CCI]" doc:name="Set Payload"/>
<logger message="#[payload.message]" level="DEBUG" doc:name="Msg Log"/>
<custom-transformer class="com. vanrish.transformer.CciTransformer" doc:name="Java Transformer"/>
</processor-chain>
</scatter-gather>
<choice doc:name="Choice">
<when expression="#[payload is List]">
<logger level="INFO" message="i am list" doc:name="Logger"/>
<expression-component doc:name="Company Msg Exp"><![CDATA[payload=app.dserializeObjectToXML(message.payload[0]));]]></expression-component>
</when>
<otherwise>
<logger message="CompanyMsg class" level="INFO" doc:name="Logger"/>
<expression-component doc:name="Company Msg Exp"><![CDATA[payload=app.dserializeObjectToXML(message.payload));]]></expression-component>
</otherwise>
</choice>
<set-variable variableName="messageType" value="Company" doc:name="Variable"/>
Rajnish Kumar is CTO of Vanrish Technology with Over 25 years experience in different industries and technology. He is very passionate about innovation and latest technology like APIs, IOT (Internet Of Things), Artificial Intelligence (AI) ecosystem and Cybersecurity. He present his idea in different platforms and help customer to their digital transformation journey.