Isaias
Isaias

Reputation: 55

Exit Iterate mediator after aggregation *with the Aggregated Message* (without continueParent) - WSO2

Is it possible to continue the flow after the iterate+aggregate mediator with the aggregated message so I can continue using the resulting message?

Or do I have to do all the processing inside the aggregate mediator and use the continueParent property to continue the processing in some other way?

Sample code of what I'm trying to achieve. Notice that I can't execute anything bellow the iterate sequence (and even if I use continueParent="true", the payload logged bellow is not the iterated+aggregated payload, it turns out it is the payload that was there before the iterate)...:

<iterate description="" expression="//n1:Entry" id="ENTRY_ITERATOR" 
xmlns:n1="http://ws.apache.org/ns/synapse">
<target>
    <sequence>
        <sequence key="myValidationSequence"/>
        <log>
            <property expression="$ctx:RESULT" name="Validation Result:"/>
        </log>
        <switch source="$ctx:RESULT">
            <case regex="S">
                <drop/>
            </case>
            <case regex="C">
                <payloadFactory media-type="xml">
                    <format>
                        <Entry>
                            <product_code>$1</product_code>
                        </Entry>
                    </format>
                    <!-- this comes from the validationSequence -->
                    <args>
                        <arg evaluator="xml" expression="$ctx:product_code"/>
                    </args>
                </payloadFactory>
            </case>
            <default>
                <log>
                    <property name="Warning: " value="Could not identify validation code."/>
                </log>
            </default>
        </switch>
        <log level="full"/>
        <property name="RESPONSE" value="true"/>
        <sequence key="AggregationSequence"/></sequence>
</target>
</iterate>
<log>
    <property name="INFO" value="I can't get here. Why?"/>
</log>
<log level="full"/>

Here's the aggregate sequence:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="AggregationSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <aggregate id="ENTRY_ITERATOR">
        <completeCondition>
            <messageCount max="-1" min="-1"/>
        </completeCondition>
        <onComplete>
            <log>
                <property name="LOG..." value="Aggregation completed"/>
            </log>
            <log level="full"/>
        </onComplete>
    </aggregate>
</sequence>

My EI version is 6.1.1

Upvotes: 0

Views: 1035

Answers (1)

Muralidharan.rade
Muralidharan.rade

Reputation: 2336

Is it possible to continue the flow after the iterate+aggregate mediator with the aggregated message so I can continue using the resulting message? - Yes, that's the idea of using both the mediators and its possible.

The following way should work.

<iterate description="" expression="//n1:Entry" id="ENTRY_ITERATOR" 
xmlns:n1="http://ws.apache.org/ns/synapse">
<target>
    <sequence>
        <sequence key="myValidationSequence"/>
        <log>
            <property expression="$ctx:RESULT" name="Validation Result:"/>
        </log>
        <switch source="$ctx:RESULT">
            <case regex="S">
                <drop/>
            </case>
            <case regex="C">
                <payloadFactory media-type="xml">
                    <format>
                        <Entry>
                            <product_code>$1</product_code>
                        </Entry>
                    </format>
                    <!-- this comes from the validationSequence -->
                    <args>
                        <arg evaluator="xml" expression="$ctx:product_code"/>
                    </args>
                </payloadFactory>
            </case>
            <default>
                <log>
                    <property name="Warning: " value="Could not identify validation code."/>
                </log>
            </default>
        </switch>
        <log level="full"/>
        <property name="RESPONSE" value="true"/>
</target>
</iterate>

    <aggregate id="ENTRY_ITERATOR">
        <completeCondition>
            <messageCount max="-1" min="-1"/>
        </completeCondition>
        <onComplete>
            <log>
                <property name="LOG..." value="Aggregation completed"/>
            </log>
            <log level="full"/>
        </onComplete>
    </aggregate>

Please refer the below documentation of Iterate and Aggregate mediators for the better understanding of the working process.

https://docs.wso2.com/display/EI611/Iterate+Mediator https://docs.wso2.com/display/EI611/Aggregate+Mediator

Upvotes: 1

Related Questions