You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Exception Clause

You can use the Exception Clause in the Java DSL to specify the error handling you require on a per type basis using the exception() method.

For example if you want to perform a specific piece of processing if a certain exception is raised you can do this simply via

exception(ValidationException.class).
  to("activemq:validationFailed");
  
from("seda:inputA").
  to("validation:foo/bar.xsd", "activemq:someQueue");

from("seda:inputB").to("direct:foo").
  to("rnc:mySchema.rnc", "activemq:anotherQueue");

Here if the processing of seda:inputA or seda:inputB cause a ValidationException to be thrown (such as due to the XSD validation of the Validator component or the Relax NG Compact syntax validation of the Jing component), then the message will be sent to activemq:validationFailed queue.

Overloading the RedeliveryPolicy

The default error handler used in Camel is the Dead Letter Channel which supports attempting to redeliver the message exchange a number of times before sending it to a dead letter endpoint. Sometimes you want to overload the redelivery policy on a per exception type basis. By default in the above examples, if a ValidationException occurs then the message will not be redelivered; however if some other exception occurs (such as a JDBC deadlock or remote method invocation) the route will be retried.

However if you want to customize any methods on the RedeliveryPolicy object, you can do this via the fluent API...

exception(MyException.class).
  maximumRedeliveries(2);

You can mix and match these approaches; specifying a custom processor to be used after all the redeliveries fail together with customizing any aspect of the RedeliveryPolicy

  • No labels