2

I want to implement a simple "for loop" in WSO2 Integration Studio.

For example:

I am implementing a bus-route API. Every bus has 10 different stops. I want to fetch the 10 stops from the back-end service. A normal for-loop for this would be:

for(i=0;i<10;i++)
{
    //back-end call
    <call>
       <endpoint>
          <http method="get" uri-template="https://backend.com/city+i"/>
       </endpoint>
    </call>
}

NOTE: In the above for loop, the back-end call has path parameter like city which should be iterated as city1, city2, city3,..... city9.

How do I implement this in WSO2 EI/ESB Integration Studio?

Community
  • 1
  • 1
cracknut
  • 301
  • 2
  • 11
  • How are you storing the URLs for the backend calls? Based on that we can try to come up with an idea. – Arunan Sugunakumar May 14 '20 at 16:09
  • I have edited the for loop in the question and have also added a NOTE at bottom, please check. I'm not storing the URLs for backend calls anywhere. For backend calls, I'm using Call Mediator inside the http endpoint. Does this answer your doubt? – cracknut May 14 '20 at 16:56

1 Answers1

2

One simple way would be to define a sample payload with the numbers inside an array and iterate through it. (This would work if the number of the iterations are predefined) For eg: [{"value" : 1},{"value" :2},{"value" : 3}, ... ]

Or else you can write a custom class mediator and implement your logic.

Also there is a fun way to implement a while loop with the help of database. http://bsenduran.blogspot.com/2017/08/while-loop-in-wso2-esb.html?m=1

Arunan Sugunakumar
  • 3,311
  • 3
  • 12
  • 20