This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Iterate Mediator

The Iterate Mediator implements another EIP and will split the message into number of different messages derived from the parent message by finding matching elements for the XPath expression specified. New messages will be created for each and every matching element and processed in parallel using either the specified sequence or endpoint. Parent message can be continued or dropped in the same way as in the clone mediator.

The preservePayload attribute specifies if the original message should be used as a template when creating the splitted messages, and defaults to false, in which case the splitted messages would contain the split elements as the SOAP body.



Syntax

<iterate [continueParent=(true | false)] [preservePayload=(true | false)] (attachPath="xpath")? expression="xpath">
   <target [to="uri"] [soapAction="qname"] [sequence="sequence_ref"] [endpoint="endpoint_ref"]>
     <sequence>
       (mediator)+
     </sequence>?
     <endpoint>
       endpoint
     </endpoint>?
   </target>+
 </iterate>

UI Configuration

The Iterate Mediator can be configured with the following options:

  • Continue Parent - Specifies whether the original message should be continued or dropped.
    • True
    • False

      Tip

      This is default to false.

  • Preserve Payload - Specifies whether the original message should be used as a template when creating the splitted messages or not.
    • True
    • False

      Tip

      This is default to false.

  • Iterate Expression - XPath expression that matches the elements, which you want to split the message from.
  • Attach Path - You can specify an XPath expression for elements that the splitted elements (as expressed in Iterate expression) are attached to, to form new messages.

Tip

You can click this link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have used in the XPath expression.

Each Iterate Mediator has its own Target by Default

Here you can prepare a message to send to an endpoint or mediate through some more sequences.

  • SOAP Action - The SOAP action of the message.
  • To Address - The target endpoint address.
  • Sequence - Mediates the message through a sequence. You can either pick a named sequence from the registry or define an anonymous sequence by adding mediators to the current Target mediator as children.
  • Endpoint - Sends the message to an endpoint. Here you can pick a named endpoint from the registry or keep the endpoint as anonymous.

    Tip

    You can add in the Endpoint panel that can be accessed from the Manage-> Mediation-> Endpoints menu in the left hand side menu bar.

Note

You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.


Example

<iterate expression="//m0:getQuote/m0:request" preservePayload="true"
         attachPath="//m0:getQuote"
         xmlns:m0="http://services.samples">
    <target>
        <sequence>
            <send>
                <endpoint>
                    <address
                        uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
            </send>
        </sequence>
    </target>
</iterate>

In this scenario, the Iterate Mediator splits the messages in to parts and process them asynchronously.