jetblack87
jetblack87

Reputation: 1

Camel - Handling irrecoverable errors

I’m working on Camel and focusing on Error Handling.

For irrecoverable errors (those that won’t be fixed by retries), Camel In Action says you should use exchange.getOut().setFault(true) and exchange.getOut().setBody("Error Occurred").

What is the best way to actually handle these errors? Right now I’m thinking there’s two ways:

  1. Using handleFaults(true) on the route or context then handling like any other errors
  2. The original message sender could handle it if Request Reply pattern is used

1 is straight forward to me (except at that point, might as well use Exceptions/Recoverable errors?). 2 is a little trickier – I’m not sure how the original sender will know that the message that they get back is an error (vs. the expected return message).

What I’m thinking could happen is this using Exception to indicate that it’s an error:

In route:

// error occurred
exchange.getOut().setFault(true);
exchange.getOut().setBody(new Exception(“error”));

In sender (jms example using QueueRequestor for Request Reply):

responseMessage = qRequestor.request(msg);
if(responseMessage instanceof ObjectMessage && ((ObjectMessage)responseMessage).getObject() instanceof Exception) {
  // AN ERROR OCCURRED IN ROUTE
} else {
   // NORMAL PROCESSING OF MESSAGE
}

This just seems like a lot of work on the original sender. Is there a better way of handling this?

Upvotes: 0

Views: 500

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

Camel can handle the exception well out of box with the help of ErrorHandler, which means your camel route don't need to do much thing about it. But for the fault message, it's a part of Application level message, Camel ErrorHandler don't want to touch it, so the developer should think about how to handle it.

Upvotes: 1

Related Questions