Exception from recipientList EIP of camel not caught at route level

Viewed 403

Camel Version 2.22.0
Runtime: SpringBoot : 2.0.2.RELEASE
JDK version: 1.8.0_121

EIP: recipientList.

Problem: Exception raised from parallel process of recipientList is not caught at route level onException clause.

Below is the 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"));
}
2 Answers

Try make onException as global like this:

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. 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. 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. If you enable the "shareUnitOfWork" option (on the recipientList), exceptions should be propagated.

Related