xml DSL中的Camel谓词示例

Him*_*dav 5 java spring apache-camel

如何实现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();
Run Code Online (Sandbox Code Playgroud)

小智 6

所需的简单元素(见接受的答案)是

<simple>${header.type} == 'widget'</simple>
Run Code Online (Sandbox Code Playgroud)

注意字段表达式如何被$ {}包围,后跟OGNL语法进行比较,这不是字段表达式本身的一部分.


Kon*_*hov 5

像这样:

<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>
Run Code Online (Sandbox Code Playgroud)