Ashok.N
Ashok.N

Reputation: 1391

How to maintain same Correlation id's after using Splitter and few other Components?

I am using Spring Integration XPath Splitters and Header Enrichers as below:

    <!-- split the folders-->
    <int-xml:xpath-splitter input-channel="PQAdditionalContactHistory-Split-Filtered-Folders-Channel" output-channel="PQAdditionalContactHistory-Split-Filtered-Folders-Channel" >
    <int-xml:xpath-expression expression="//response/results/PQCallHistory/row"/>
    </int-xml:xpath-splitter>

<int:chain  input-channel="PQAdditionalContactHistory-Split-Filtered-Folders-Channel" output-channel="PQContactHistory-InputChannel" >
    <int:service-activator  ref="msgHandler" method="buildMessageFromExtSysResponse" />
    <int-xml:xslt-transformer xsl-resource="${stylesheet.PQAdditionalContactHistory-To-PQContactHistory-Request}" />
</int:chain>   

<int:channel id="PQContactHistory-InputChannel" />              
    <int:chain input-channel="PQContactHistory-InputChannel" output-channel="PQContactHistory-OutputChannel">

        <int-xml:xpath-splitter>
            <int-xml:xpath-expression expression="//PQCallHistory"  namespace-map="xmlMessageNamespace" />
        </int-xml:xpath-splitter>

        <int-xml:xslt-transformer xsl-resource="${stylesheet.PQContactHistoryStoredProcData}"  />

        <!-- Store the original payload in header for future purpose -->
        <int:header-enricher default-overwrite="true"  should-skip-nulls="true"  >
            <int:header name="${headerNames.originalPayload}" expression="payload" />   
        </int:header-enricher>  
    </int:chain>            

Here, the plan is to use an aggregator and combine all the split messages after performing some operations using those split messages. The surprise here is all the list of split messages are not arriving at the aggregator at once. When I investigated further to know the root cause, I found that the correlation id's of the split messages are changed after second splitter. But, I need all the list of messages split by first splitter arriving as one chunk at the aggregator end. Any ideas on how to accomplish this? Please let me know if my question is not clear.

I am using default <aggregator> behaviour:<int:aggregator input-channel="test" ref="xmlAggregator" method="aggreagateAdditionalFolders"></int:aggregator>.

Upvotes: 0

Views: 1351

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121427

That's truth, because any splitter provides SequenceDetails(sequenceId, sequenceSize etc) by default within its scope and stores them in the MessageHeaders via stack manner.

Unfortunately the <int-xml:xpath-splitter> doesn't support apply-sequence="false" yet.

But you can follow with JIRA workaround for that Pull Request.

That's only one side for overcoming your use-case.

Another matter is around the <aggregator>. There is need to know how you correlate and release group there.

I may guess you just rely on default <aggregator> behaviour - getting deal with that SequenceDetails headers.

That's not good. After the first xpath-splitter, the sequenceSize header has gotten the value as a number of reply messages. Since you are going to split each of them one more time, there is no info how much items will come to the <aggregator>.

The same is about a sequenceNumber header, which means a marker for <aggregator> to apply the message to the goup or not.

So, show, please, your aggregator configuration. And after that we'll try to provide the solution together.

Anyway in this case you should provide some custom ReleaseStrategy for aggregator. The CorrelationStrategy may remain as default one.

UPDATE

The sample how to configure XPathMessageSplitter as a generic bean:

<int:service-activator>
    <beans:bean class="org.springframework.integration.xml.splitter.XPathMessageSplitter">
        <beans:constructor-arg type="org.springframework.xml.xpath.XPathExpression">
            <int-xml:xpath-expression expression="//PQCallHistory" namespace-map="xmlMessageNamespace" />
        </beans:constructor-arg>
    </beans:bean>
</int:service-activator>

Upvotes: 1

Related Questions