2013-12-20 36 views
0

我想学习Apache骆驼路由。对于一个基本的例子,我想知道如何根据XML标签中的值进行路由。例如,如果我们有父标签3个XML文件:基于标记值的路由消息 - Apache Camel

<item type="n1" /> 
<item type="n2" /> 
<item type="n3" /> 

我想航线这3分为3个不同的管道...

所以这里是我的想法(春季):

<route id="NormalizeMessageData"> 

<from uri="jms:incomingOrders" /> 
<convertBodyTo type="java.lang.String" /> 

<choice> 
<when> 
    <simple>${body} contains '?xml'</simple> <!-- to make sure its xml file only --> 
    * 
    * 
    * 
    <unmarshal> 
    <jaxb contextPath="org.fusesource.camel" /> 
    </unmarshal> 
    <to uri="jms:orders" /> 
</when> 
</choice> 

看到星星(*),这是我们需要进行一些检查的地方。但是如何?

+0

看一看在[XPath的组件(http://camel.apache.org/ xpath.html)。 – Ralf

回答

2

见上面链接的所有细节骆驼XPath文档,但你应该只需要像:

<choice> 
    <when> 
     <xpath>/item/@type = 'n1'</xpath> 
     ... 
    </when> 
</choice> 
+0

嗯。 ' // item [@ type ='n1']''?这也会起作用吗? –