简体   繁体   English

未在路由级别捕获骆驼的收件人列表 EIP 的异常

[英]Exception from recipientList EIP of camel not caught at route level

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

EIP: recipientList. EIP:收件人列表。

Problem: Exception raised from parallel process of recipientList is not caught at route level onException clause.问题:在路由级别 onException 子句中未捕获从收件人列表的并行进程引发的异常。

Below is the DSL下面是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"));
}

Try make onException as global like this:尝试将 onException 设为全局,如下所示:

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: So you need to disable error handlers in recipient routes. UPD:因此您需要禁用收件人路由中的错误处理程序。 Try like this (can't insert normally code sample)尝试像 这样(不能正常插入代码样品)

That's a classical mistake: (exactly like the split EIP) each recipient will process a copy of the original Exchange.这是一个典型的错误:(与拆分 EIP 完全一样)每个收件人都将处理原始 Exchange 的副本 Any failure on these copies will not affect (raise an exception on) the route processing the master Exchange, as every single exchange runs in a completely separate unit of work.这些副本上的任何故障都不会影响(引发异常)处理Exchange 的路由,因为每个单独的 Exchange 都在完全独立的工作单元中运行。 If you enable the " shareUnitOfWork " option (on the recipientList), exceptions should be propagated.如果启用“ shareUnitOfWork ”选项(在收件人列表上),则应传播异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM