Mule - 将一个大的JSON列表拆分为多个较小的JSON列表

use*_*140 1 mule mule-studio mule-el

我有一个包含大约200个对象的json对象列表.我想将该列表拆分为较小的列表,其中每个列表每个包含最多20个对象.我想将每个子列表POST到基于HTTP的端点.

<flow name="send-to-next-step" doc:name="send-to-vm-flow">
    <vm:inbound-endpoint exchange-pattern="one-way"
        path="send-to-next-step-vm" doc:name="VM" />
    <!-- received the JSON List payload with 200 objects-->
    <!-- TODO do processing here to split the list into sub-lists and call sub-flow for each sub-list
    <flow-ref name="send-to-aggregator-sf" doc:name="Flow Reference" />
</flow>
Run Code Online (Sandbox Code Playgroud)

一种可能的方法是我编写一个迭代列表的java组件,并在迭代每个20个对象之后调用子流.有没有更好的方法来实现这一目标?

Rya*_*ter 6

如果您的有效负载是Java集合,则Mule foreach作用域具有内置批处理:http://www.mulesoft.org/documentation/display/current/Foreach

例:

<foreach batchSize="20">
   <json:object-to-json-transformer/>
   <http:outbound-endpoint ... />
</foreach>
Run Code Online (Sandbox Code Playgroud)