Apache Camel 2.3 - How to ignore exceptions

Error handling is notoriously hard and Camel have extensive support to configure and handle situations differently when a failure occur.

One such feature is the onException which allows you among others to define policies what to do when a given set of exception occurs. For example you can define individual redelivery settings, to say that ConnectionException should try up till 5 times with a backoff multiplier of 2.

In cases where we give up (exhaust) you can let Camel route the messages which allows you to do some custom processing when we failed. In these situations you can also indicate you want to handle the exception. That means the exception is removed from the Exchange and you can provide a custom failure message, to a waiting caller. For example if you do request/reply over TCP where you need to return a custom format in case of failure.

But there are situations where you just want to ignore and continue if a given exception was thrown. And up till now that was only possible to do using the doTry .. doCatch in Camel. However in Camel 2.3 we now have a new option on onException called continued, which allows you to tell Camel, that it should ignore the exception and just continue routing to the next processor in the route.

We picked the name continued because the similar option was named handled. And when using continued its automatic handled as well. And you can only configure one of them.

You can read more about this at the Camel wiki page, at the section Handle and continue exceptions.

Another feature which I have meant to write about for some time is the Event Notifer, which allows you to subscribe to events in Camel. For example you can be notifier about routes being started and stopped etc. Also fine grained events about Exchanges being routed as well. For example when an Exchange is being sent to an endpoint. Suppose we want to log all those events and how long time it took to sent it to the endpoints. I have created an example in the cookbook page at Camel. You can find it here.

PS: If you do not grasp the Camel error handling, then the chapter 5 in the Camel in Action book has received great reviews and people generally understand the error handling much better after reading it.

No comments: