2012-05-10 10 views
5

Come posso implementare seguente predicato Esempio given nella primavera del DSL:Camel Predicate Esempio in 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(); 

risposta

4

Ti piace questa:

<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

Il contesto dell'applicazione Spring non ha un attributo name nell'intestazione e non esiste affatto. –

+0

Quali sono le tue versioni di cammello e primavera? –

+0

Ad ogni modo si può provare questo in invece del predicato: $ {header.type == 'wombat'}

6

L'elemento semplice richiesta (vedi accepted answer) è

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

Nota come l'espressione del campo è circondata da $ {} seguita da O Sintassi GNL per il confronto, che non fa parte dell'espressione del campo stesso.

+1

$ {header.type == 'widget'} non funziona. Usa $ {header.type} == 'widget' come menzionato da Dhiraj. – jaks