You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by enalposi <en...@yahoo.com> on 2011/07/15 15:42:35 UTC

RouteBuilder Predicate Syntax

[Camel 2.7.2]

Sorry, but I am not quite clear about the syntax of inserting Predicates,
esp to dynamically wire in processors... I am also not sure about the
significance of end() and the newer endChoice(). Basically, doing 1 choice
seems to be working but 2, as in below examples, breaks the continuation of
the route "to".

I am trying to build something along the line of:
- if predicate 'condition1' is true go through processor1 otherwise skip to
the next
- if predicate 'condition2' is true go through processor2 regardless of
condition1
- after evaluation of the predicates, join back into a common route
definition segment.

Example:

from("in").
    choice().when(condition1).process(processor1).end().
    choice().when(condition2).process(processor2).end().
to("to");

OR


from("in").choice().
    when(condition1).process(processor1).
    when(condition2).process(processor2).
end().to("to");


Hope I was able to explain my issue :)

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-Predicate-Syntax-tp4590722p4590722.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: RouteBuilder Predicate Syntax

Posted by enalposi <en...@yahoo.com>.
Yes, I suppose that's another option, or wrap things with a
DelegateProcessor.

Our route builder (on top of the Camel RouteBuilder) is part of a larger
framework and makes all sorts of dynamic and configured decisions how to
assemble various scenarios.

Cheers!

--
View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-Predicate-Syntax-tp4590722p4600844.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: RouteBuilder Predicate Syntax

Posted by boday <be...@initekconsulting.com>.
choice and predicate are used to do conditional routing based on attributes
of an exchange/message, not static attibutes resolved on route startup...

I'm not following what you are trying to do...why would a Processor be NULL
exactly?  If a code change is required to add/remove/implement a processor,
then you can modify your route along with that change.  Otherwise, just
create a simple processor that can handle the logic of checking the "state"
of a processor before routing to it (using ProducerTemplate, etc)


enalposi wrote:
> 
> Ok, so I initially used #1 but it failed to build the route. The issue
> seems to be different than what I originally assumed...
> 
> Basically I am building a route and want to insert a processor based upon
> a condition (which is: does the processor exist?). Initially I did this
> with an if-then-else statement but didn't like repeating most of the route
> definition - so I tried choice().
> 
> The condition (processor exists) is known at route build time, so I
> implemented a BooleanPredicate, which would return true if the related
> processor is defined/injected or false if it is null. The choice would now
> route through the processor if it was not null. However, apparently
> RouteBuilder does not like the processor being null, even if it never
> routes through it. This kind of makes sense, since choice is meant to work
> dynamically on message content. So what I did instead now is remove the
> choice() and just insert a DummyProcessor, if the worker processor is
> null.
> 
> Is this a reasonable way to address the issue or is there a better way?
> 
> Thanks!
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-Predicate-Syntax-tp4590722p4600131.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: RouteBuilder Predicate Syntax

Posted by enalposi <en...@yahoo.com>.
Ok, so I initially used #1 but it failed to build the route. The issue seems
to be different than what I originally assumed...

Basically I am building a route and want to insert a processor based upon a
condition (which is: does the processor exist?). Initially I did this with
an if-then-else statement but didn't like repeating most of the route
definition - so I tried choice().

The condition (processor exists) is known at route build time, so I
implemented a BooleanPredicate, which would return true if the related
processor is defined/injected or false if it is null. The choice would now
route through the processor if it was not null. However, apparently
RouteBuilder does not like the processor being null, even if it never routes
through it. This kind of makes sense, since choice is meant to work
dynamically on message content. So what I did instead now is remove the
choice() and just insert a DummyProcessor, if the worker processor is null.

Is this a reasonable way to address the issue or is there a better way?

Thanks!

--
View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-Predicate-Syntax-tp4590722p4599593.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: RouteBuilder Predicate Syntax

Posted by boday <be...@initekconsulting.com>.
#1 is correct, you should explicitly call end() after each choice() block...


enalposi wrote:
> 
> [Camel 2.7.2]
> 
> Sorry, but I am not quite clear about the syntax of inserting Predicates,
> esp to dynamically wire in processors... I am also not sure about the
> significance of end() and the newer endChoice(). Basically, doing 1 choice
> seems to be working but 2, as in below examples, breaks the continuation
> of the route "to".
> 
> I am trying to build something along the line of:
> - if predicate 'condition1' is true go through processor1 otherwise skip
> to the next
> - if predicate 'condition2' is true go through processor2 regardless of
> condition1
> - after evaluation of the predicates, join back into a common route
> definition segment.
> 
> Example:
> 
> from("in").
>     choice().when(condition1).process(processor1).end().
>     choice().when(condition2).process(processor2).end().
> to("to");
> 
> OR
> 
> 
> from("in").choice().
>     when(condition1).process(processor1).
>     when(condition2).process(processor2).
> end().to("to");
> 
> 
> Hope I was able to explain my issue :)
> 
> Thanks!
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/RouteBuilder-Predicate-Syntax-tp4590722p4592073.html
Sent from the Camel - Users mailing list archive at Nabble.com.