Mule - split a big JSON list into multiple smaller JSON lists

六月ゝ 毕业季﹏ 提交于 2019-12-04 19:05:53

If your payload is a Java Collection, the Mule foreach scope has batching built in: http://www.mulesoft.org/documentation/display/current/Foreach

Example:

<foreach batchSize="20">
   <json:object-to-json-transformer/>
   <http:outbound-endpoint ... />
</foreach>

You could use the Groovy collate method for the batching, and then foreach or collection-splitter, depending on your needs:

<json:json-to-object-transformer returnClass="java.util.List"/>
<set-payload value="#[groovy:payload.collate(20)]"/>
<foreach>
   <json:object-to-json-transformer/>
   <http:outbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8082" path="xx"/>
</foreach>
<set-payload value="#[groovy:payload.flatten()]"/>

This will send each batch of 20 objects to the http endpoint and then flatten back to the original list.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!