Hi Just a quick updated on this one. I have commited a enhancment in CAMEL-1419 that allows predicates to use type coercion for its binary operators. This allows you to test eg String containing a number with an Integer and so on. It work with enum as well.
This allows to do content based routing a bit easier as the when() can test even if the types dont match up. So you can test a boolean against "true" etc. This will be in Camel 2.0 Claus Ibsen-2 wrote: > > On Fri, Feb 27, 2009 at 5:22 PM, ee7arh <[email protected]> > wrote: >> >> Hi, >> >> I'm getting quite into using the Camel DSL router and got quite far but >> now >> have this situation: > Welcome onboard the ride. > >> >> I have a bean method (myBeanMethod1()) which returns not a boolean but a >> real object (MyReturnObj1). This object contains an Enum return code >> (myReturnCode) and I want to do some routing based on this returncode. >> >> e.g. >> >> // Bean Method >> public MyReturnObj1 myBeanMethod1(); >> >> The definition of MyReturnObj1 is >> >> public class MyReturnObj1 { >> >> protected Enum myReturnCode; >> >> } >> >> I want to do some routing like this: >> >> from("jms:queue:queue1").to("bean:myBeanMethod1").choice() >> .when(myErrorCode=myReturnCode.ERRROR1).to("jms:queue:error1Queue") >> .when(myErrorCode=myReturnCode.ERROR2).to("jms:queue:error2Queue") >> .otherwise().to("jms:queue:unknownErrorQueue"); >> >> Is it possible to somehow do routing based on bean which returns an >> object? >> If I set my "returnCode" into the JMS Header field I could use the >> header() >> method to get the values as seen in many examples on Camel website. > Yes when you do routing with the content based router EIP pattern, you > use the choice/when/otherwise as you do above. > when and otherwise uses Predicate to evaluate true|false, if it should > route it this way or continue down the other predicates. > > Camel have build in nice DSL sugar for these predicates, aka predicate > builders and others so you can build fluent syntax. > > You can use a method call predicate to invoke a method on a bean, and > then chain the sub predicate isEqualTo. > > when(method(MyPredicateBean.class, > "thismethod").isEqualTo(MyEnumConstant)).to("jms:xxx") > > But this will invoke your bean on each predicate test and if you think > this operation is very expensive, then you can do as above > to route it to your bean prior the choice and set the result in a header. > > Then the testing is just based using header("key") instead of the > method call predicate. > > > > >> >> Advice greatly appreciated. > > >> >> Andrew >> >> -- >> View this message in context: >> http://www.nabble.com/Camel-Routing-based-on-bean-return-object-tp22249110p22249110.html >> Sent from the Camel - Users (activemq) mailing list archive at >> Nabble.com. >> >> > > > > -- > Claus Ibsen > Apache Camel Committer > > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > > -- View this message in context: http://www.nabble.com/Re%3A-Camel-Routing-based-on-bean-return-object-tp22249549p23610268.html Sent from the Camel - Users mailing list archive at Nabble.com.
