blob: ddc41a4810987861597fc65c600cc69c8f8cb1a9 [file] [log] [blame]
<div class="wiki-content maincontent"><h3 id="SampleCamelRoutes-ExampleofaconfigurationthatshowhowtouseCamelrouteswithJuelandXpath.">Example of a configuration that show how to use Camel routes with Juel and Xpath.</h3>
<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
&lt;beans&gt;
&lt;!-- Allows us to use system properties as variables in this configuration file --&gt;
&lt;bean class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;/&gt;
&lt;broker useJmx=&quot;true&quot; persistent=&quot;false&quot; xmlns=&quot;http://activemq.org/config/1.0&quot;
brokerName=&quot;localhost&quot; dataDirectory=&quot;${activemq.base}/data&quot;&gt;
&lt;/broker&gt;
&lt;camelContext id=&quot;camel&quot; xmlns=&quot;http://activemq.apache.org/camel/schema/spring&quot;&gt;
&lt;!-- simple bridge from a topic to queue --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming&quot;&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld&quot;&gt;
&lt;/route&gt;
&lt;!-- Dependencies: camel-juel-[camel-n].jar, juel-[juel-n]-impl.jar, juel-[juel-n].jar must be in the activemq lib directory --&gt;
&lt;!-- 2 separate JUEL based filters --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel1&quot;&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;foo&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myHeaderField.equals(&#39;takeMe&#39;)}&lt;/el&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel1.fooMsgs&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;bar&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myHeaderField.equals(&#39;takeMe&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myOtherHeaderField.equals(&#39;3&#39;)}&lt;/el&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel1.fooMsgs.special&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using 2 separate xpath based filters, assuming the message has an XML body --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel2&quot;&gt;
&lt;filter&gt;
&lt;xpath&gt;$JMSType = &#39;foo&#39; and $myCustomHeader=&#39;takeMe&#39;&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel2.fooMsgs&quot;&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;xpath&gt;$JMSType = &#39;bar&#39; and $myCustomHeader=&#39;takeMe&#39;&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel2.barMsgs&quot;&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using choice route based on xpath --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel3&quot;&gt;
&lt;choice&gt;
&lt;when&gt;
&lt;xpath&gt;$JMSType = &#39;foo&#39;&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel3.fooMsgs&quot;&gt;
&lt;/when&gt;
&lt;otherwise&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel3.nonFooMsgs&quot;&gt;
&lt;/otherwise&gt;
&lt;/choice&gt;
&lt;/route&gt;
&lt;!-- route using choice route based on JUEL --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel4&quot;&gt;
&lt;choice&gt;
&lt;when&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;foo&#39;)}&lt;/el&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel4.fooMsgs&quot;&gt;
&lt;/when&gt;
&lt;/choice&gt;
&lt;/route&gt;
&lt;!-- route using nested JUEL based filters --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel5&quot;&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;foo&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.OperationRequest.equals(&#39;foo1&#39;)}&lt;/el&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel5.foo1Msgs&quot;&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.OperationRequest.equals(&#39;foo2&#39;)}&lt;/el&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel5.foo2Msgs&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using nested JUEL and xpath filters, including a filter which examines the message content for an xml attribute --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel6&quot;&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;foo&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode[@myAttributeKey=&#39;myAttributeValue&#39;]&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel6.fooMsgs&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using nested JUEL and xpath filters, including a filter which examines the message content for an xml value --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel7&quot;&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;Tideworks.GateVision.XmlCmd&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode/elementKey = &#39;elementValue&#39;&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel7.fooMsgs&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using nested JUEL and xpath filters, including a filter which examines the message content for an xml attribute --&gt;
&lt;route&gt;
&lt;from uri=&quot;activemq:topic:topic.HelloWorld.incoming.camel8&quot;&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals(&#39;foo&#39;)}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode[@myAttributeKey=&#39;myAttributeValue&#39;]/grandchildXMLBodyNode[@myAttributeKey=&#39;myAttributeValue&#39;]&lt;/xpath&gt;
&lt;to uri=&quot;activemq:queue:queue.HelloWorld.camel8.fooMsgs&quot;&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;/camelContext&gt;
&lt;/beans&gt;
]]></script>
</div></div></div>