简体   繁体   English

WSO2 EI/ESB:用于循环实现

[英]WSO2 EI/ESB: For loop implementation

I want to implement a simple " for loop " in WSO2 Integration Studio.我想在 WSO2 Integration Studio 中实现一个简单的“ for 循环”。

For example:例如:

I am implementing a bus-route API.我正在实施一条公交路线 API。 Every bus has 10 different stops.每辆公共汽车有 10 个不同的站点。 I want to fetch the 10 stops from the back-end service.我想从后端服务中获取 10 个站点。 A normal for-loop for this would be:一个正常的for循环是:

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.注意:在上面的 for 循环中,后端调用有路径参数,如 city,应该迭代为 city1、city2、city3、.....city9。

How do I implement this in WSO2 EI/ESB Integration Studio?如何在 WSO2 EI/ESB 集成工作室中实现这个?

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}, ... ] (如果迭代次数是预定义的,这将起作用)例如:[{"value": 1},{"value":2},{"value": 3}, ... ]

Or else you can write a custom class mediator and implement your logic.否则,您可以编写自定义 class 中介并实现您的逻辑。

Also there is a fun way to implement a while loop with the help of database.还有一种有趣的方法可以在数据库的帮助下实现 while 循环。 http://bsenduran.blogspot.com/2017/08/while-loop-in-wso2-esb.html?m=1 http://bsenduran.blogspot.com/2017/08/while-loop-in-wso2-esb.html?m=1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM