0

ルートの実行をログに記録するときにこの変数を呼び出すことができるように、キャメル コード内に変数を設定しようとしています。この変数は、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>
4

1 に答える 1

1

次のようにラクダのコンテキストで setHeader を使用することで、これが機能するようになりました。 <setHeader headerName="id"><xpath>//id/text()</xpath></setHeader> <log message="Routed ${header.id} to Test queue"/>

于 2014-10-13T19:26:05.507 に答える