1

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. enter image description here

<?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>
Utsav
  • 1,593
  • 4
  • 22
  • 46
  • Can you describe the name pattern of the files? – Víctor Romero Dec 17 '14 at 19:09
  • it is normal .txt file – Utsav Dec 18 '14 at 05:45
  • I mean the name pattern. How are you supposed to telate those two files? – Víctor Romero Dec 18 '14 at 11:11
  • in my scenario i have 2 files one is first.txt and second is second.txt i want to read the content of both and combine in one and print – Utsav Dec 18 '14 at 11:59
  • what if another batch of files arrives at the same time, will them ovewrite first.txt and second.txt? are there going to be others three.txt and fouth.txt? – Víctor Romero Dec 18 '14 at 12:16
  • Yes whatever the files come at the same time in the location from where Mule is picking we have to combine them using aggregator, doen't matter how many files are there just combine all. – Utsav Dec 18 '14 at 12:55
  • How long take the files to arrive? and how often do they arrive? i.e: they are arriving every 10 minutes and the transference of the n files is taking 1 minute. In a case like this, are you ok waiting up to 61 seconds for any other potential file to arrive? – Víctor Romero Dec 18 '14 at 13:13
  • It has to wait for all incoming files till 2 seconds , or to implement this you can go ahead with your own mock timestamp – Utsav Dec 18 '14 at 14:28

1 Answers1

2

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"/>
Víctor Romero
  • 5,107
  • 2
  • 22
  • 32
  • what is the use of MULE_CORRELATION_GROUP_SIZE and here in the above script you are setting the setCorrelationGroupSize if i am correct both are same , just want to know the use of setting the Group Size – Utsav Dec 22 '14 at 13:52