Apache camel 驼峰的recipientList EIP异常未在路由级别捕获

Apache camel 驼峰的recipientList EIP异常未在路由级别捕获,apache-camel,Apache Camel,骆驼版本2.22.0 运行时:SpringBoot:2.0.2.RELEASE JDK版本:1.8.0_121 EIP:recipientList 问题:从recipientList的并行进程引发的异常未在路由级别的OneException子句中捕获 下面是DSL @Override public void configure() throws Exception { restConfiguration().clientRequestValidation(true) //.c

骆驼版本2.22.0
运行时:SpringBoot:2.0.2.RELEASE
JDK版本:1.8.0_121

EIP:recipientList

问题:从recipientList的并行进程引发的异常未在路由级别的OneException子句中捕获

下面是DSL

@Override
public void configure() throws Exception {

    restConfiguration().clientRequestValidation(true)
     //.contextPath("/pss/v1.0/")
     .port("8080").host("0.0.0.0")
     .enableCORS(true)
     .apiContextPath("/api-doc")
     .apiProperty("api.title", "Test REST API")
     .apiProperty("api.version", "v1")
     .apiContextRouteId("doc-api")
     .component("servlet")
     .bindingMode(RestBindingMode.json);
    
    rest("/api/").clientRequestValidation(true)
     .id("api-route")
     .consumes("application/json")
     .get("/bean/{name}")
     .bindingMode(RestBindingMode.json)
     .to("direct:remoteService");
    
    from("direct:remoteService")
     .onException(Exception.class).handled(true)
     .log("Exception Caught : ${exception.message}")
     .end()
     .recipientList(constant("direct:route1, direct:route2"), ",").parallelProcessing().aggregationStrategy(new GroupedBodyAggregationStrategy())
     .stopOnException()
     .end()
     .log("The final Exchange data : ${exception.message}");
    
    from("direct:route1")
     .setHeader( Exchange.CONTENT_ENCODING, simple("gzip"))
     .setBody(simple("RESPONSE - [ {  \"id\" : \"bf383eotal length is 16250]]"))
     .log("${body}");
    
    from("direct:route2")
     .log("${body}")
     .process(e-> {
        List<String> myList = new ArrayList();
        
        myList.add("A");
        myList.add("b");
        myList.add("C");
        
        e.getIn().setBody(myList);
     })
     .split(body())
     .parallelProcessing(true)
     .aggregationStrategy(new GroupedBodyAggregationStrategy())
     .stopOnException()
     .log("${body}")
     .choice()
     .when(simple("${body} == 'b'"))
     .throwException(new Exception("jsdhfjkASDf"));
}
@覆盖
public void configure()引发异常{
restConfiguration().clientRequestValidation(true)
//.contextPath(“/pss/v1.0/”)
.端口(“8080”).主机(“0.0.0.0”)
.enableCORS(正确)
.apiContextPath(“/api doc”)
.apiProperty(“api.title”、“测试REST api”)
.apiProperty(“api.version”、“v1”)
.apiContextRouteId(“doc api”)
.组件(“servlet”)
.bindingMode(RestBindingMode.json);
rest(“/api/”).clientRequestValidation(true)
.id(“api路线”)
.使用(“应用程序/json”)
.get(“/bean/{name}”)
.bindingMode(RestBindingMode.json)
。至(“直接:远程服务”);
来自(“直接:远程服务”)
.onException(Exception.class).handled(true)
.log(“捕获异常:${Exception.message}”)
(完)
.recipientList(常量(“direct:route1,direct:route2”),“,”).parallelProcessing().aggregationStrategy(新GroupedBodyAggregationStrategy())
.stopOnException()
(完)
.log(“最终交换数据:${exception.message}”);
从(“直接:路由1”)
.setHeader(Exchange.CONTENT_编码,简单(“gzip”))
.setBody(简单(“响应-[{\'id\':\'bf383eotal length is 16250]]))
.log(“${body}”);
从(“直接:路由2”)
.log(“${body}”)
.过程(e->{
List myList=new ArrayList();
myList.添加(“A”);
myList.添加(“b”);
myList.添加(“C”);
e、 getIn().setBody(myList);
})
.split(body())
.parallelProcessing(真)
.aggregationStrategy(新的GroupedBodyAggregationStrategy())
.stopOnException()
.log(“${body}”)
.choice()
.when(简单(${body}=='b'))
.ThroweException(新异常(“jsdhfjkASDf”);
}

尝试将OneException设置为全局,如下所示:

onException(Exception.class).handled(true)
.log("Exception Caught : ${exception.message}")
.end();

    from("direct:remoteService")
.recipientList(constant("direct:route1, direct:route2"), ",").parallelProcessing().aggregationStrategy(new GroupedBodyAggregationStrategy())
.stopOnException()
.end()
.log("The final Exchange data : ${exception.message}")
;

UPD:因此您需要禁用收件人路由中的错误处理程序。请尝试类似(无法插入正常的代码示例)

这是一个典型错误:(与拆分EIP完全相同)每个收件人将处理原始Exchange的副本。这些副本上的任何失败都不会影响(在上引发异常)处理交换的路由,因为每个交换在一个完全独立的工作单元中运行。
如果启用“
shareUnitOfWork
”选项(在recipientList上),则应传播异常。

这是可行的。但我们需要在路由范围本身处理异常。非常感谢。此方法与UPD中的方法一样有效,并且是一条新信息。现在尝试此方法,但无效。谢谢