Resequencer in Mule






Resequencer in Mule



Resequencer holds a group of message and re sequences them using each message's correlation sequence property.

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 reorder 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.

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.



flow of resequencer




Splitter and Collection aggregator we have discussed in other tutorials too.So here i am going to show only Resequencer configuration.



URL : http://localhost:8085/api/resequencer
Method : POST

Input :


<Employees> <Employee> <FirstName>Himanshu</FirstName> <LastName>Pal</LastName> <Salary>120000</Salary> </Employee> <Employee> <FirstName>Sonam</FirstName> <LastName>Sharma</LastName> <Salary>200000</Salary> </Employee> <Employee> <FirstName>Piyush</FirstName> <LastName>Joshi</LastName> <Salary>300000</Salary> </Employee> <Employee> <FirstName>Vinod</FirstName> <LastName>Shukla</LastName> <Salary>800000</Salary> </Employee> <Employee> <FirstName>Kunal</FirstName> <LastName>Verma</LastName> <Salary>500000</Salary> </Employee> </Employees>


Output :





XML project code :



<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd"> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/> <file:connector name="File" writeToDirectory="src/main/resources/splitted" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/> <flow name="test_resequencerFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/resequencer" doc:name="HTTP"/> <splitter expression="#[xpath('//Employee')]" doc:name="Splitter"/> <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/> <file:outbound-endpoint path="src/main/resources/splitted" connector-ref="File" responseTimeout="10000" doc:name="File"/> <resequencer failOnTimeout="true" doc:name="Resequencer"> </resequencer> <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/> <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/> </flow> </mule>