camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Outram <apa...@nickoutram.name>
Subject Re: Exception based routing
Date Thu, 09 Aug 2007 08:52:01 GMT



James.Strachan wrote:
> 
> 
> I'm wondering about something like...
> 
> // lets setup the error handler first
> onError(MyException.class).maximumRedeliveries(5).onFail().to("seda:c")
> 
> // now lets do the route
> from("foo").to("bar");
> 
> I guess if we define the error handler in the middle of a route we
> might need some kinda escape expression to go back to the 'real route'
> from the error handler route. e.g.
> 
> // this is bad...
> from("foo").
> 	onError(MyException.class).maximumRedeliveries(5).onFail().to("seda:c").
>   to("bar"); // by default this would still be part of the error handler
> 
> maybe something like
> 
> from("foo").
> 	onError(MyException.class).
> 	  maximumRedeliveries(5).onFail().to("seda:c").
> 	onError(Bar.class).
> 	  to("seda:d")
> 	onSucccess().
> 	  to("bar");
> 
> i.e. the onError(Class) stuff starts adding an error route for a
> specific type of exception (which also allows you to configure retry
> policy & the dead letter destination etc)
> 
> Thoughts?
> 
> 

That works too. I particularly like the onError(... construct as it keeps
the configuration of the error handling maxRedeliveries etc. out of the
route definition 'from("foo").to("bar");'.

Not so hot on your second example for the same reason... in-lining the
onError(... mixes routing semantics with configuration and makes the DSL
messy.

It also strikes me that the onError(… approach could be further expanded to
handle more generalised matches i.e.

// lets setup the error handler first 
onPattern(error(MyException.class)).maximumRedeliveries(5).onFail().to("seda:c") 

// lets trap any messages with settlement amounts more than £100000
onPattern(xpath("/settlementAmnt >10000”).to(“seda:authorisationRequired”);

// now lets do the route 
from("foo").process(new myEnricher()).to("bar");

The ‘onPattern(…’ would trap matching messages anywhere on the route at
‘node’ transitions; sort of AOP for routing.

-N


-- 
View this message in context: http://www.nabble.com/Exception-based-routing-tf4226796s22882.html#a12068759
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message