gpt4 book ai didi

apache-camel - 是否可以对 Java 对象使用 Camel 循环?

转载 作者:行者123 更新时间:2023-12-02 21:17:22 25 4
gpt4 key购买 nike

我使用 Spring+Camel 和 Java 应用程序,但我不明白如何在 Camel 配置中使用 Loop。Camel 文档建议:

<route>
<from uri="direct:b"/>
<loop>
<header>loop</header>
<to uri="mock:result"/>
</loop>
</route>

如何调整适合我情况的循环?

<route>
<from uri="myjms:queue:{{myqueue.name1}}"/>
...
<method bean="myProcessor" method="getSomeMyObjects"> <!-- returns Collection<MyObject> -->
<loop>
<header>?????</header> <!-- get single MyObject?.. how???.. -->
<to uri="myjms:queue:{{myqueue.name2}}"/>
</loop>
</rout>

bean 内:

<bean id="myProcessor" class="my.package.MyProcessor">

我实现了以下方法:

getSomeMyObjects()         - returns Collection<MyObject>;
getSomeMyObject(int index) - returns single MyObject;
getSomeMyObjectsCount() - returns the number of objects inside Collection<MyObject>;

如果需要的话可以实现任何其他方法。

是否可以在Camel配置中使用循环来解决这个问题?

最佳答案

您不需要使用循环。您需要将每个 MyObject 拆分为不同的正文并发送它们。使用splitter模式。

<route>
<from uri="myjms:queue:{{myqueue.name1}}"/>
...
<method bean="myProcessor" method="getSomeMyObjects"> <!-- returns Collection<MyObject> -->
<split>
<simple>${body}</simple>
<to uri="myjms:queue:{{myqueue.name2}}"/>
</split>
</rout>

关于apache-camel - 是否可以对 Java 对象使用 Camel 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29821455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com