I think you need to fill the gap of design time and run time.
Usually, Camel predicate just check the run time exchange to decide to return 
true or false.
But you can write a custom Predicate just check the localVar value and ignore 
the exchange parameter to implement the route feature that you want.  


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Monday, August 19, 2013 at 10:00 AM, peacock.snowdrift wrote:

> Hello,
>  
> Complete Camel newbie here, so apologies if this is a silly question.
>  
> I have a piece of code along the lines of:
>  
> if (localVar == value) {
> from(uri)
> ... stuff here...
> .to(destination);
> .to(additionalDestination);
> } else {
> from(uri)
> ... stuff here...
> .to(destination)
> }
>  
> I've tried using a Predicate on the localVar value to tidy up this
> definition - as I'm duplicating code with 2 virtually identical routes apart
> from small differences otherwise - but can't seem to access it:
>  
> Predicate predicate = {what goes here?};
>  
> from(uri)
> ... stuff here...
> .to(destination)
> .choice()
> .when(predicate).to(additionalDestination);
>  
> Can I do so, or is there a better way of making this statement more
> graceful?
>  
> Thanks for any assistance.
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Conditional-routing-and-local-variables-tp5737490.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to