ule子-将一个较大的JSON列表拆分为多个较小的JSON列表 [英] Mule - split a big JSON list into multiple smaller JSON lists
问题描述
我有一个包含约200个对象的json对象列表.我想将该列表拆分为较小的列表,其中每个列表最多包含20个对象.我想将每个子列表发布到基于HTTP的端点.
I have a list of json objects containing about 200 objects. I want to split that list into smaller lists where each list contains max 20 objects each. I would like to POST each sublist to HTTP based endpoint.
<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>
一种可能的方式是,我编写一个Java组件,该组件在列表上进行迭代,并在对每个20个对象进行迭代之后,调用子流.有没有更好的方法可以做到这一点?
One possible way is that I write a java component which iterates over the list and after iterating over each 20 objects, call sub-flow. Is there any better way of accomplishing this?
推荐答案
如果您的有效载荷是Java集合,则Mule foreach 范围已内置批处理:
If your payload is a Java Collection, the Mule foreach scope has batching built in: http://www.mulesoft.org/documentation/display/current/Foreach
示例:
<foreach batchSize="20">
<json:object-to-json-transformer/>
<http:outbound-endpoint ... />
</foreach>
这篇关于ule子-将一个较大的JSON列表拆分为多个较小的JSON列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!