Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel Predicate Example in xml DSL

How can I implement following Predicate Example given in Spring DSL:

Predicate isWidget = header("type").isEqualTo("widget");

from("jms:queue:order")
   .choice()
      .when(isWidget).to("bean:widgetOrder")
      .when(isWombat).to("bean:wombatOrder")
   .otherwise()
      .to("bean:miscOrder")
   .end();
like image 897
Himanshu Yadav Avatar asked May 10 '12 13:05

Himanshu Yadav


2 Answers

Like this:

<route>
  <from uri="jms:queue:order"/>
  <choice>
    <when>
       <simple>${header.type} == 'widget'</simple>
       <to uri="bean:widgetOrder"/>
    </when>
    <when>
      <simple>${header.type} == 'wombat'</simple>
      <to uri="bean:wombatOrder"/>
    </when>
    <otherwise>
      <to uri="bean:miscOrder"/>
    </otherwise>
  </choice>
</route>
like image 118
Konstantin V. Salikhov Avatar answered Sep 30 '22 01:09

Konstantin V. Salikhov


The required simple element (see accepted answer) is

<simple>${header.type} == 'widget'</simple>

Notice how the field expression is surrounded by ${} followed by OGNL syntax for comparison, which is not part of the field expression itself.

like image 34
Dhiraj Bokde Avatar answered Sep 30 '22 03:09

Dhiraj Bokde