0
votes

I read data from salesforce and split it using collection splitter. I want to aggregate all data into single list. First I count all records and I set that counter with MULE_CORRELATION_GROUP_SIZE. But my counter gives me wrong count..And my data didn't aggregate.. How can I solve this problem

Is my following flow right?

Following is my code

<flow name="davesalesforceFlow1Tmp" doc:name="davesalesforceFlow1Tmp">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" path="test" contentType="text/plain"  />
        <sfdc:query config-ref="salesforce" doc:name="Salesforce" query="My query"/>

        <collection-splitter doc:name="Collection Splitter"/>
        <set-session-variable variableName="cnt"
                          value="#[org.mule.util.StringUtils.countMatches(message.payload, '\n') + org.mule.util.StringUtils.countMatches(message.payload, ',') - 1]" doc:name="Session Variable"/>

        <set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
                  value="#[sessionVars.cnt]" doc:name="Property"/>
        <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>

I also tried following code But in output got only single record

 <flow name="davesalesforceFlow1Tmp" doc:name="davesalesforceFlow1Tmp">
            <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" path="test" contentType="text/plain"  />
            <sfdc:query config-ref="salesforce" doc:name="Salesforce" query="My query"/>

            <collection-splitter doc:name="Collection Splitter"/>
            <set-property propertyName="MULE_CORRELATION_GROUP_SIZE"
                  value="#[message.outboundProperties['MULE_CORRELATION_SEQUENCE']]" doc:name="Property"/>
            <collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
<logger message="MY PAYLOAD IS  #[payload]" level="INFO" doc:name="Logger"/>
  </flow>

    </flow>
1
You should see if the for each scope is a better fit for what you're ultimately trying to accomplish.afelisatti

1 Answers

0
votes

If you use the collection splitter and aggregator together theres no need to keep track of the count or anything.

Mule will take care of this via the MULE_CORRELATION_* header behind the scenes.

Only if you are dong for complex splits and aggregates may you need to modify these headers yourself.

        <logger level="INFO" message="size before: #[payload.size()]" />

        <collection-splitter />

        <logger level="INFO" message="Individual item: #[payload]" />

        <collection-aggregator />

        <logger level="INFO" message="size after: #[payload.size()]" />