blob: 6b5dbc4bb827e1078254559ce10ce7698125fe76 [file] [log] [blame]
<div class="wiki-content maincontent"><h2 id="Selectors-JMSSelectors">JMS Selectors</h2>
<p>Selectors are a way of attaching a filter to a subscription to perform content based routing. Selectors are defined using SQL 92 syntax and typically apply to message headers; whether the standard properties available on a JMS message or custom headers you can add via the JMS code.</p>
<p>Here is an example</p>
<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[
JMSType = &#39;car&#39; AND color = &#39;blue&#39; AND weight &gt; 2500
]]></script>
</div></div>
<p>For more documentation on the detail of selectors see the reference on <a shape="rect" class="external-link" href="http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html" rel="nofollow">javax.jmx.Message</a>. <br clear="none">
ActiveMQ supports some JMS defined properties, as well as some ActiveMQ ones - see <a shape="rect" href="activemq-message-properties.xml">message properies </a> - that the selector can use.</p>
<h3 id="Selectors-UsingXPathtofiltermessages">Using XPath to filter messages</h3>
<p>Apache ActiveMQ also supports XPath based selectors when working with messages containing XML bodies. To use an XPath selector use the following syntax</p>
<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[
XPATH &#39;//title[@lang=&#39;&#39;eng&#39;&#39;]&#39;
]]></script>
</div></div>
<div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Xalan dependency</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body">
<p>XPath support requires <a shape="rect" class="external-link" href="http://xalan.apache.org/index.html">Xalan</a> which is not part of the distribution. The Xalan jars needs to be manually added to lib directory or pulled into your app via maven </p>
<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;dependency&gt;
&lt;groupId&gt;xalan&lt;/groupId&gt;
&lt;artifactId&gt;xalan&lt;/artifactId&gt;
&lt;version&gt;2.6.0&lt;/version&gt;
&lt;/dependency&gt;]]></script>
</div></div></div></div>
<h3 id="Selectors-StringPropertyConversions/SelectingAgainstSTOMPmessages">String Property Conversions / Selecting Against STOMP messages</h3>
<p>The JMS spec states that a String property should not get converted to a numeric when used in a selector. So for example, if a message has the 'age' property set to String '21' then the following selector should not match it: 'age &gt; 18'. Since ActiveMQ support STOMP client which can only send messages with string properties, that restriction is a bit limiting. If you want your JMS selectors to auto-convert String properties the the appropriate number type, just prefix the the selector with 'convert_string_expressions:'. If you changed selector in the previous example to be 'convert_string_expressions:age &gt; 18', then it would match the message.</p></div>