Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel - Exception handling in 'sub routes'

Tags:

apache-camel

Camel explicitly handles two 'scopes' of error handling:

  • Global
  • per Route

The issue I'm having is exceptions thrown in a 'sub route'. For instance, I've got this route:

from("direct:sendToWebservice").
    .processRef("massageBeforeSending").
    .to("http://webservice.com").
    .processRef("massageResponse");

Then I've got two other routes that need to send messages to the webservice:

from(direct:fromSystemA").
    .errorHandler(deadLetterChannel("direct:TellSystemA")).
    .to("direct:sendToWebservice");

from(direct:fromSystemB").
    .errorHandler(deadLetterChannel("direct:TellSystemB")).
    .to("direct:sendToWebservice");

What I would like to happen is, if the webservice route throws an exception, it's propagated up to the caller, and either system A or system B would be notified. I don't see a way to achieve this.

I feel like this would be a common use case - has anyone bumped up against it before?

Thanks again for your time,

Roy

like image 368
Roy Truelove Avatar asked Sep 13 '11 19:09

Roy Truelove


People also ask

How does Apache handle error in camel?

Using onException to handle known exceptions is a very powerful feature in Camel. You can mark the exception as being handled with the handle DSL, so the caller will not receive the caused exception as a response. The handle is a Predicate that is overloaded to accept three types of parameters: Boolean.

What is redelivery in camel?

A redelivery policy defines rules when Camel Error Handler perform redelivery attempts. For example you can setup rules that state how many times to try redelivery, and the delay in between attempts, and so forth. You can use redelivery policies at two places in Camel: Error Handler. onException.

What is Java DSL in camel?

Camel uses a Java Domain Specific Language or DSL for creating Enterprise Integration Patterns or Routes in a variety of domain-specific languages (DSL) as listed below: Java DSL - A Java based DSL using the fluent builder style.


1 Answers

Got the answer from a colleague: The subroute needs to have it's error handling disabled:

from("direct:sendToWebservice").
    .errorHandler(noErrorHandler())     // disables error handling for this route
    .processRef("massageBeforeSending").
    .to("http://webservice.com").
    .processRef("massageResponse");

This forces Camel to propagate the error to the calling route.

like image 77
Roy Truelove Avatar answered Sep 21 '22 14:09

Roy Truelove