2012-05-10 69 views
5

我如何能实现以下谓词例given在Spring DSL:骆驼谓词实例XML 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(); 

回答

4

像这样:

<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> 
+0

Spring应用程序上下文在标头中没有名称属性,根本不存在。 –

+0

你的骆驼和春天的版本是什么? –

+0

无论如何,您可以在而不是谓词中尝试此操作: $ {header.type =='wombat'}

6

所需的简单元素(见accepted answer)是

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

请注意字段表达式是如何被$ {}包围的,后面跟着O用于比较的GNL语法,它不是字段表达式本身的一部分。

+1

$ {header.type =='widget'}不起作用。如Dhiraj所述,使用 $ {header.type} =='widget'。 – jaks