camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Re: Exception based routing
Date Mon, 06 Aug 2007 22:14:19 GMT
Hi Neil

On 8/6/07, Neil Thorne <mr_neil_thorne@hotmail.com> wrote:
>
> Hi,
>
> I work with Nick Outram - we've a splitter of sorts working (with our own
> processor)
>
> I have the requirement where on a route from A to B there are a couple of
> different exceptions that can be thrown.

Funny - I was just thinking about that today. I've been working on
some XML validation components for XSD/Relax and wanted a nice way to
route based on validation exceptions...


> a) a system exception gets thrown. A system exception indicates an
> infrastructure problem that will be fixed ASAP as it is essential to the
> correct functioning of the system as a whole. eg. jdbc connection failed,
> remote system is down etc. If a system exception is thrown then that
> operation should be continually retried until it is successful.
>
> b) a business exception is thrown. A business exception indicates that there
> was a problem with the request itself. It should not be retried (at least
> not until the problem has been resolved). The message should be moved onto a
> hospital queue where it can be inspected, changed and retried after possible
> manual intervention.

BTW how can you tell the difference between a) and b)? Are there
certain base exception types you can use?


> What is the simplest way to achieve this with camel? Currently I can only
> see an errorHandler which assumes you want to dump messages that cannot be
> processed to an error endpoint.

An ErrorHandler could do anything - e.g. based on the type of
exception it could decide whether or not to retry (if at all) etc.

The default implementation is DeadLetterChannelErrorHandler, which
assumes n-retries with optional backoff delays - before sending to a
'dead letter' endpoint, which is kinda like your hospital queue


>  Can I bind an ErrorHandler to a specific
> type of exception on the same route somehow?

Firstly you can customize the errorHandler on a set of routes, or a
specific route, or within the processing of a route. So if you had
your own idea errorHandler implementation you could use it wherever
you like

Currently there's no 'exception-type-based error handler'
implementation; but it should be easy to add such a thing. e.g. we
could add a Set<Class> property to the DeadLetterChannel for
exceptions which should not be retried maybe?


> If I could then I suppose I could move business exceptions immediately to
> the hospital queue (with a retry count of zero).
>
> I could also bind a different error handler with an infinite retry count
> (-1?).

Yeah - I've been pondering similar things. I'm wondering if we should
have some kinda version of the Content Based Router that uses a
similar notation to try/catch/finally; where known business related
exceptions are caught and the message forwarded to a 'business logic
failed' type endpoint, otherwise system exceptions (which are way more
random and harder to catch all) filter up to the default errorHandler
- such as for retrying & dead letter channels etc.

e.g. in XML I was pondering something like

<try>
  <!-- do some stuff here which may throw exceptions -->

  <catch error="org.foo.bar.SomeBusinessException">
    <!-- for business level exceptions, send to some reject queue -->
    <to uri="activemq:myRejections'/>
  </catch>

  <!-- any other system exceptions cause the error handler to retry n-times -->
</try>

Thoughts?

-- 
James
-------
http://macstrac.blogspot.com/

Mime
View raw message