blob: 97fa4fafbdae03edc8b8ec0c11eefbc0079acaf5 [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">
<pre class="brush: java; gutter: false; theme: Default" style="font-size:12px;">
&lt;beans&gt;
&lt;!-- Allows us to use system properties as variables in this configuration file --&gt;
&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/&gt;
&lt;broker useJmx="true" persistent="false" xmlns="http://activemq.org/config/1.0"
brokerName="localhost" dataDirectory="${activemq.base}/data"&gt;
&lt;/broker&gt;
&lt;camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"&gt;
&lt;!-- simple bridge from a topic to queue --&gt;
&lt;route&gt;
&lt;from uri="activemq:topic:topic.HelloWorld.incoming"&gt;
&lt;to uri="activemq:queue:queue.HelloWorld"&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="activemq:topic:topic.HelloWorld.incoming.camel1"&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('foo')}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myHeaderField.equals('takeMe')}&lt;/el&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel1.fooMsgs"&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('bar')}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myHeaderField.equals('takeMe')}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.myOtherHeaderField.equals('3')}&lt;/el&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel1.fooMsgs.special"&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="activemq:topic:topic.HelloWorld.incoming.camel2"&gt;
&lt;filter&gt;
&lt;xpath&gt;$JMSType = 'foo' and $myCustomHeader='takeMe'&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel2.fooMsgs"&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;xpath&gt;$JMSType = 'bar' and $myCustomHeader='takeMe'&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel2.barMsgs"&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;!-- route using choice route based on xpath --&gt;
&lt;route&gt;
&lt;from uri="activemq:topic:topic.HelloWorld.incoming.camel3"&gt;
&lt;choice&gt;
&lt;when&gt;
&lt;xpath&gt;$JMSType = 'foo'&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel3.fooMsgs"&gt;
&lt;/when&gt;
&lt;otherwise&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel3.nonFooMsgs"&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="activemq:topic:topic.HelloWorld.incoming.camel4"&gt;
&lt;choice&gt;
&lt;when&gt;
&lt;el&gt;${in.headers.JMSType.equals('foo')}&lt;/el&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel4.fooMsgs"&gt;
&lt;/when&gt;
&lt;/choice&gt;
&lt;/route&gt;
&lt;!-- route using nested JUEL based filters --&gt;
&lt;route&gt;
&lt;from uri="activemq:topic:topic.HelloWorld.incoming.camel5"&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('foo')}&lt;/el&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.OperationRequest.equals('foo1')}&lt;/el&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel5.foo1Msgs"&gt;
&lt;/filter&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.OperationRequest.equals('foo2')}&lt;/el&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel5.foo2Msgs"&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="activemq:topic:topic.HelloWorld.incoming.camel6"&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('foo')}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode[@myAttributeKey='myAttributeValue']&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel6.fooMsgs"&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="activemq:topic:topic.HelloWorld.incoming.camel7"&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('Tideworks.GateVision.XmlCmd')}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode/elementKey = 'elementValue'&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel7.fooMsgs"&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="activemq:topic:topic.HelloWorld.incoming.camel8"&gt;
&lt;filter&gt;
&lt;el&gt;${in.headers.JMSType.equals('foo')}&lt;/el&gt;
&lt;filter&gt;
&lt;xpath&gt;/rootXMLBodyNode/childXMLBodyNode[@myAttributeKey='myAttributeValue']/grandchildXMLBodyNode[@myAttributeKey='myAttributeValue']&lt;/xpath&gt;
&lt;to uri="activemq:queue:queue.HelloWorld.camel8.fooMsgs"&gt;
&lt;/filter&gt;
&lt;/filter&gt;
&lt;/route&gt;
&lt;/camelContext&gt;
&lt;/beans&gt;
</pre>
</div></div></div>