如何将多个修改后的消息发送到骆驼中的一个端点?

How to send multiple modified messages to one endpoint in camel?

在我的应用程序中,我根据给定的数据结构查询服务以获取一些标识号。对于每个返回的标识号,我想根据用标识号丰富的查询数据向同一收件人发送一封邮件消息:

from("direct:querySource")
.enrich("direct:executeQueryIds", new IdWithDataAggregator())
// here I stuck - want to send the original received message from 
// the querySource n (executeQueryIds) times enrich by iterating
// over executeQueryIds result
.to("smtp://...")
.end()

我尝试使用基于特定消息 header 的 split 拆分消息,但在拆分中我只得到拆分的 header 值 body,不是原始消息。使用带有聚合器的 split 调用作为第二个参数都效果不佳,因为第二个交换是 null.

我也尝试过 loop 结构,但我觉得应该有一种更方便、更通俗易懂的方法。

提前致谢!

如果您想将一条消息变成多条消息,您仍然需要使用拆分器。你可能想做这样的事情:

from(START)
 .split(). method(SplitBean.class, "splitMessage")
 .to(FINISH);

您可以将 headers 传入 bean 方法并以这种方式手动拆分消息。