注入永不聚合的拆分器 [英] Inject a splitter that never aggregates

查看:20
本文介绍了注入永不聚合的拆分器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Camel ver 2.17.3:我想在路由中插入一个拆分器,以便拆分消息保持拆分.如果我有一个带有拆分器的直接"路由,当控制从内部路由返回时,我不再有拆分消息,只有原始消息.

Camel ver 2.17.3: I want to insert a splitter into a route so that split messages remain split. If I have a "direct" route with a splitter, when control returns from the inner route, I no longer have split messages, only the original.

from("direct:in")
.transform(constant("A,B,C"))
.inOut("direct:inner")
.log("RET-VAL: ${in.body}");

from("direct:inner")
.split()
.tokenize(",")      
.log("AFTER-SPLIT ${in.body}")
;

基于 类似问题的答案,以及下面克劳斯的评论,我尝试插入我自己的聚合器并始终将组标记为完成".只有最后一个(拆分)消息被返回到外部路由.

Based on the answer to a similar question, and Claus's comment below, I tried inserting my own aggregator and always marking the group "COMPLETE". Only the last (split) message is being returned to the outer route.

from("direct:in")
.transform(constant("A,B,C"))
.inOut("direct:inner")
.log("RET-VAL: ${in.body}");

from("direct:inner")
.split(body().tokenize(","), new MyAggregationStrategy())
.log("AFTER-SPLIT ${in.body}")
;


public static class MyAggregationStrategy implements AggregationStrategy
{
  @Override
  public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
    System.out.println("Agg called with:"+newExchange.getIn().getBody());
    newExchange.setProperty(Exchange.AGGREGATION_COMPLETE_CURRENT_GROUP, true);
    return newExchange;
  }
}

无论路由如何嵌套等,我如何让消息保持分离?

How do I get the messages to stay split, regardless of how routes are nested etc.?

推荐答案

查看此 EIPhttp://camel.apache.org/composed-message-processor.html

使用仅拆分器示例.

AggregationStrategy 中,您将所有这些拆分的子消息组合成一条消息,这就是您想要的结果,例如拆分器完成后的传出消息.您如何做到这一点取决于您的消息以及您想要保留的内容.例如,您可以将子消息放在 List 中,或者可能是基于 XML 的,然后您可以附加 XML 片段或其他内容.

And in the AggregationStrategy you combine together all those splitted sub-messages into one message which is the result you want, eg the outgoing message of the splitter when its done. How you do that depends on your messages and what you want to keep. For example you can put together the sub messages in a List or maybe its XML based and you can append the XML fragments, or something.

这篇关于注入永不聚合的拆分器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆