最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Which mediator to use for calling endpoints inside an iterate loop? - Stack Overflow

programmeradmin1浏览0评论

I'm using WSO2 Micro Integrator (WSO2 MI) and need to call multiple endpoints within an <iterate> loop. The goal is to dynamically send requests to different API endpoints extracted from a JSON payload.

I have an <iterate> mediator that loops through JSON data and extracts tokenEndpoint, client_id, and client_secret. I need to send a request to each endpoint within the loop.

<iterate expression="json-eval($)">
<target>
<sequence>
<log level="custom">
<property expression="json-eval($.tokenEndpoint)" name="tokenEndpoint"/>
</log>
<!-- Set Headers & Body for Token Request -->
<property name="Content-Type" scope="transport" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="Accept" scope="transport" type="STRING" value="application/json"/>
<!-- Extract API Credentials -->
<property expression="json-eval($.tokenEndpoint)" name="TokenEndpoint" scope="default" type="STRING"/>
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
<property expression="json-eval($.client_secret)" name="client_secret" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="json" expression="$.client_id"/>
<arg evaluator="json" expression="$.client_secret"/>
</args>
</payloadFactory>
<log level="full">
<property expression="json-eval($.body)" name="Token Request Payload"/>
</log>
<!-- Call API - Which Mediator to Use Here? -->
<call>
<endpoint>
<address uri="{TokenEndpoint}"/>
</endpoint>
</call>
</sequence>
</target>
</iterate>

Should I use the mediator or mediator?

Is there another recommended approach?

Should I use an explicit definition, or is there a better way to dynamically set the URL from JSON?

How do I ensure each API call executes independently inside the loop without waiting for the previous one to finish?

I'm using WSO2 Micro Integrator (WSO2 MI) and need to call multiple endpoints within an <iterate> loop. The goal is to dynamically send requests to different API endpoints extracted from a JSON payload.

I have an <iterate> mediator that loops through JSON data and extracts tokenEndpoint, client_id, and client_secret. I need to send a request to each endpoint within the loop.

<iterate expression="json-eval($)">
<target>
<sequence>
<log level="custom">
<property expression="json-eval($.tokenEndpoint)" name="tokenEndpoint"/>
</log>
<!-- Set Headers & Body for Token Request -->
<property name="Content-Type" scope="transport" type="STRING" value="application/x-www-form-urlencoded"/>
<property name="Accept" scope="transport" type="STRING" value="application/json"/>
<!-- Extract API Credentials -->
<property expression="json-eval($.tokenEndpoint)" name="TokenEndpoint" scope="default" type="STRING"/>
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
<property expression="json-eval($.client_secret)" name="client_secret" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="json" expression="$.client_id"/>
<arg evaluator="json" expression="$.client_secret"/>
</args>
</payloadFactory>
<log level="full">
<property expression="json-eval($.body)" name="Token Request Payload"/>
</log>
<!-- Call API - Which Mediator to Use Here? -->
<call>
<endpoint>
<address uri="{TokenEndpoint}"/>
</endpoint>
</call>
</sequence>
</target>
</iterate>

Should I use the mediator or mediator?

Is there another recommended approach?

Should I use an explicit definition, or is there a better way to dynamically set the URL from JSON?

How do I ensure each API call executes independently inside the loop without waiting for the previous one to finish?

Share Improve this question edited yesterday Mark Rotteveel 109k226 gold badges155 silver badges219 bronze badges asked yesterday RoyRoy 212 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the Call mediator. Also, you need the Aggregate mediator to aggregate the responses from the endpoints.

You can follow this blog to get an idea about a similar Integration.

https://medium.com/think-integration/how-to-train-your-micro-integrator-b8c28cadca00

Note: If you are using Call mediator, then the aggregation should happen inside the InSequence itself.

发布评论

评论列表(0)

  1. 暂无评论