4
votes

The below markup is my iterate mediator which is inside a proxy service set up within WSO2 ESB 4.9.0.

I'm attempting to loop through an array of form submissions and POST them into a RESTful API also defined within the ESB. However, even though I'm using the CALL mediator, the API logs show that all my iterate requests are firing milliseconds apart - which to me indicates that the iterate mediator is actually running my inline target sequence asynchronously despite setting sequential="true".

Is there any way to ensure that the call to my REST API completes before iterating and submiting another request?

 <iterate continueParent="true"
          id="IterateRequestSink"
          expression="//*[local-name()='Submission']"
          sequential="true">
    <target>
       <sequence>
          <property name="DISABLE_CHUNKING"
                    value="true"
                    scope="axis2"
                    type="STRING"/>
          <property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
          <payloadFactory media-type="xml">
             <format>
                <params xmlns="">
                   <description>$1</description>
                   <return_call>$2</return_call>
                   <mobile>$3</mobile>
                   <sub_category>$4</sub_category>
                   <first_name>$5</first_name>
                   <last_name>$6</last_name>
                   <category>$7</category>
                </params>
             </format>
             <args>
                <arg evaluator="xml" expression="//*[local-name()='description']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='return_call']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='mobile']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='sub_category']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='first_name']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='last_name']/text()"/>
                <arg evaluator="xml" expression="//*[local-name()='category']/text()"/>
             </args>
          </payloadFactory>
          <property name="messageType"
                    value="application/x-www-form-urlencoded"
                    scope="axis2"
                    type="STRING"/>
          <call>
             <endpoint>
                <address uri="http://localhost:8280/crm/request" format="rest"/>
             </endpoint>
          </call>
          <log level="full"/>
       </sequence>
    </target>
 </iterate>
2

2 Answers

4
votes

I was using the call mediator and didn't realise there was an option for making the request blocking. This has resolved the concurrency issues.

Edit
In light of the comments below, this is the call mediator which solved the issue for me:

<call blocking="true">
  <endpoint>
    <address uri="http://localhost:8280/crm/request" format="rest"/>
  </endpoint>
</call>

Strangely enough this isn't actually documented in the latest WSO2 ESB documentation for the call mediator, which is a little unhelpful. But just look for the relevant drop down when in the mediator configuration UI or just set the option as above directly in the source.

1
votes

Try using callout[1][2] mediator instead of the call mediator. Callout mediator will do blocking external service invocations. And be mindful that usage of blocking service calls might affect the performance.

[1] - https://docs.wso2.com/display/ESB490/Callout+Mediator [2] - https://docs.wso2.com/display/ESB490/Sample+430%3A+Callout+Mediator+for+Synchronous+Service+Invocation