【问题标题】:Exception from recipientList EIP of camel not caught at route level骆驼的收件人列表 EIP 的异常未在路由级别捕获
【发布时间】:2020-06-25 19:01:38
【问题描述】:

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

EIP:收件人列表。

问题: 在路由级别的 onException 子句中没有捕获从收件人列表的并行进程引发的异常。

以下是 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"));
}

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    尝试像这样将 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:因此您需要禁用收件人路由中的错误处理程序。试试this(不能正常插入代码示例)

    【讨论】:

    • 这行得通。但我们需要在路由范围本身处理异常。
    • 非常感谢。这种方法在 UPD 中是有效的,它是一条新信息。
    【解决方案2】:

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

    【讨论】:

    • 现在尝试了这种方法,但没有奏效。谢谢
    猜你喜欢
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 2013-08-13
    • 1970-01-01
    • 2016-12-21
    相关资源
    最近更新 更多