Apache camel 如何防止驼峰拆分器在处理后聚合?

Apache camel 如何防止驼峰拆分器在处理后聚合?,apache-camel,spring-camel,Apache Camel,Spring Camel,我通过以下方式设置了骆驼路线: List<SomeRouteInfo> routes = getRouteInfo(); //I crete the routes using the info in the list. for ( SomeRouteInfo info : routes ){ RouteDefinition routeDef = from(info.from()); routeDef .errorHandler(someErrorHa

我通过以下方式设置了骆驼路线:

List<SomeRouteInfo> routes = getRouteInfo(); //I crete the routes using the info in the list.
for ( SomeRouteInfo info : routes ){
    RouteDefinition routeDef = from(info.from());

    routeDef
        .errorHandler(someErrorHandler);
        .routeId(info.getId());

    if (info.someCondition()){
        routeDef
            .split().method(someSplitterBean)
            .process(processorBean1) //The message seems split here.
    }

    routeDef
        .process(processorBean2) //The message is no longer split here. I need it to be.
        .to(info.to())
}
List routes=getRouteInfo()//我使用列表中的信息创建路线。
对于(SomeRouteInfo:routes){
RoutedDefinition routeDef=from(info.from());
路特道夫
.errorHandler(someErrorHandler);
.routeId(info.getId());
if(info.someCondition()){
路特道夫
.split().method(someSplitterBean)
.process(processorBean1)//此处的消息似乎被拆分。
}
路特道夫
.process(processorBean2)//此处不再拆分消息。我需要它。
.to(info.to())
}
基本上,有些线路我希望拆分器出现在上面,有些线路我不希望。消息本身中不存在是否拆分消息的信息

所以,问题是当我在processorBean1中处理时,似乎有多条消息。不幸的是,似乎在processorBean2中,我没有相同的。取而代之的是,我把原来的邮件正文拿了回来

我不希望拆分的消息在processorBean2中单独出现异常而不破坏其他任何东西。因此,我希望它在processorBean2上是独立的消息。我能做些什么来适应它呢?

是的,默认返回原始消息。驼峰文档中的“”对此进行了解释

我假设拆分器在
if
块中
routeDef
配置的末尾隐式地“关闭”

因此,您的路线实际上如下所示:

...
.routeId()
.split().method(someSplitterBean)
    .process(processorBean1) // here you got splitted messages
.end // end splitter; from here you got the original message (before split)
.process(processorBean2) 
.to(info.to())
因此,对于您的情况,您有多种可能性:

1:将
processorBean2
移动到拆分器内的(info.to())
。即直接在
处理器Bean1
下方。这样,拆分器仍然返回原始消息,但您不再使用它

.split().method(someSplitterBean)
    .process(processorBean1) // here you got splitted messages
    .process(processorBean2) 
    .to(info.to())
.end // end splitter; from here you got the original message (before split)
在您的情况下,您需要从拆分器开始,对路由的所有其余部分设置条件

routeDef
    .errorHandler(someErrorHandler);
    .routeId(info.getId());

if (info.someCondition()){
    routeDef.to("direct:mySplitRoute")
} else {
    routeDef.to("direct:myStandardRoute")
}
2:您添加自己的聚合器策略以返回一个包含拆分消息而不是原始消息的集合。但是,拆分器只能返回一条消息。如此。唯一可以得到它们的地方是分配器内部的

.split(method(someSplitterBean), new MyStrategy())
...
3:将“分割路径”和“非分割路径”(路径生成器中的条件)划分为两个独立的子路径,只需将“.to”([subroute])设为条件

routeDef
    .errorHandler(someErrorHandler);
    .routeId(info.getId());

if (info.someCondition()){
    routeDef.to("direct:mySplitRoute")
} else {
    routeDef.to("direct:myStandardRoute")
}

通过这种方式,您在两个路由中获得了一些冗余,但另一方面,您对(显然)不同的消息类型进行了完全分离的处理

我试过写一篇纠缠不清的文章。但是聚集者在有效的地方创造了一个自身的块。就像拆分器一样。你知道如何编写一个不会这样做的聚合器吗?我编辑了我的答案。您无法在拆分器之后获取拆分的消息。但是,您可以返回消息集合或比原始消息更有用的其他内容。最终从拆分块内部将消息发送到seda队列。