Message Chunk Splitter & Message Chunk Aggregator in Mule
Message Chunk Splitter splits message in form of chunks or fixed size message.We need to define size of message in configuration settings of Message Chunk Splitter.
Message Chunk Aggregator aggregates the splitted message in original form.
The Aggregators module contains different types of aggregators capable of storing values and releasing them all together based on the configuration specified. An Aggregator is a component used to collect those values until a condition is met, then execute a processor’s chain with the list of aggregated elements as the payload.
An Aggregator is a pass-through router, meaning that the same message that is processed by the aggregator is going to be processed by the components that follow it. The only modifications are the addition of some message attributes that provide information about the aggregation.
The basic aggregator configuration consists of the definition of the value that will be aggregated (extracted from the message through an expression evaluation), a condition that defines when the aggregation is considered complete, and a processor chain that will be executed once that condition is met.
flow of Message Chunk Splitter & Message Chunk Aggregator
Message Chunk Splitter configuration :
splitted files are located in a folder named splitted in src/main/resources
Message chunk aggregator configuration : As i said, nothing is required to configure inside it, so leave as it is.
URL : http://localhost:8085/api/chunksplitter
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:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" 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://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.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/splitter" autoDelete="false" streaming="false" validateConnections="true" doc:name="File"/> <flow name="test_messagechunksplitterFlow"> <http:listener config-ref="HTTP_Listener_Configuration" path="/chunksplitter" doc:name="HTTP"/> <message-chunk-splitter messageSize="256" doc:name="Message Chunk Splitter"/> <file:outbound-endpoint path="./src/main/resources/splitter" connector-ref="File" responseTimeout="10000" mimeType="application/xml" doc:name="File"/> <message-chunk-aggregator failOnTimeout="true" doc:name="Message Chunk Aggregator"/> <set-payload value="#[payload]" doc:name="Set Payload"/> </flow> </mule>