简体   繁体   中英

How to Aggregate Multiple Message in to One Message and print in Mule

Hi I am working with Any Point Studio and i have a scenario where Mule is reading from the path suppose it is reading 2 files from some path and its treating both the files as 2 separate messages i want to combine both in to one.

I also want to know the use of MULE_CORRELATION_GROUP_SIZE why we need it to define before Aggregator Component?

Please share code to achieve this using Custom Aggregator or is their any better way. 在此处输入图片说明

 <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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" version="EE-3.5.0" 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/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/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> <file:connector name="File" streaming="true" autoDelete="false" validateConnections="true" doc:name="File"/> <flow name="mule-file-aggregatorFlow1" doc:name="mule-file-aggregatorFlow1"> <file:inbound-endpoint path="\\\\mulespace\\foldername" responseTimeout="10000" doc:name="File" connector-ref="File"> </file:inbound-endpoint> <file:file-to-string-transformer doc:name="File to String"/> <message-properties-transformer doc:name="Message Properties"> <add-message-property key="MULE_CORRELATION_GROUP_SIZE" value="2" /> </message-properties-transformer> <custom-aggregator failOnTimeout="true" class="com.mine.custom.CustomAggregator" doc:name="Custom Aggregator"/> <json:object-to-json-transformer doc:name="Object to JSON"/> <logger message="#[message.payload]" level="INFO" doc:name="Logger"/> </flow> </mule> 

Use this after your file:inbound-endpoint:

<scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy"><![CDATA[long now = new java.util.Date().getTime(); 
                long mod = now % 2000; 
                message.setCorrelationId(String.valueOf(now - mod));
                message.setCorrelationGroupSize(100);
                return message;
            ]]></scripting:script>
        </scripting:component>
        <collection-aggregator timeout="3000" failOnTimeout="false" doc:name="Collection Aggregator"/>
        <combine-collections-transformer doc:name="Combine Collections"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM