需要帮助在Camel中设置变量

时间:2014-10-02 16:34:29

标签: xpath activemq jbossfuse blueprint

我正在尝试在我的camel代码中设置一个变量,以便在记录路由执行时调用此变量。需要从xpath语句设置此变量。

下面是无效的代码,我怀疑我需要设置一个等于我在日志消息中找到的xpath语句的变量,但我不知道该怎么做。

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/blueprint"
       xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="activemq"
       class="org.apache.activemq.camel.component.ActiveMQComponent">
       <property name="brokerURL" value="tcp://localhost:61616"/>
       <property name="userName" value="user"/>
       <property name="password" value="password"/>
</bean>



  <camelContext id="blueprintContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
    <route id="Test_Message_Content_Route">
      <from uri="activemq:queue:FirstQueue?username=user&amp;password=password&amp;concurrentConsumers=1&amp;maxConcurrentConsumers=5"/>
       <choice>
        <when>
                <xpath>//destination[text()='TEST']</xpath>
                <log message="Test route invoked"/>
                        <split>
                                <xpath resultType="java.lang.String">//message_payload/text()</xpath>
                                <log message="Routed $xpath{//id/text()} to TEST QUEUE"/>
                                <to uri="activemq:queue:TestQueue?username=user&amp;password=password"/>
                        </split>
        </when>
        <when>
                <xpath>//destination[text()='DEV']</xpath>
                <log message="Dev route invoked"/>
                        <split>
                                <xpath resultType="java.lang.String">//message_payload/text()</xpath>
                                <log message="Routed $xpath{//id/text()} to DEV QUEUE"/>
                                <to uri="activemq:queue:DevQueue?username=user&amp;password=password"/>
                        </split>
        </when>
        <otherwise>
                <log message="Sending message to DL Queue"/>
                <to uri="activemq:queue:DLQueue?username=user&amp;password=password"/>
        </otherwise>
       </choice>
    </route>
  </camelContext>

</blueprint>

1 个答案:

答案 0 :(得分:1)

我现在通过在我的驼峰上下文中使用setHeader来实现这一点,如下所示:     <setHeader headerName="id"><xpath>//id/text()</xpath></setHeader>     <log message="Routed ${header.id} to Test queue"/>