<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<title>ActiveMQ Artemis Static Message Selector Example</title>
<link rel="stylesheet" type="text/css" href="../common/common.css" />
<link rel="stylesheet" type="text/css" href="../common/prettify.css" />
<script type="text/javascript" src="../common/prettify.js"></script>
</head>
<body onload="prettyPrint()">
<h1>Static Message Selector Example</h1>
<pre>To run the example, simply type <b>mvn verify</b> from this directory, <br>or <b>mvn -PnoServer verify</b> if you want to start and create the server manually.</pre>
<p>This example shows you how to configure a ActiveMQ Artemis queue with static message selectors (filters)
(to configure a static selector directly on a <em>JMS</em> queue, please see the
<a href="../static-selector-jms/readme.html">static-selector-jms example</a>).</p>
<p>Static message selectors are ActiveMQ's extension to message selectors as defined in JMS spec 1.1.
Rather than specifying the selector in the application code, static message selectors are defined in one of
ActiveMQ's configuration files, broker.xml, as an element called 'filter' inside each queue
definition, like</p>
<pre class="prettyprint"><code>
<queues>
<queue name="jms.queue.selectorQueue">
<address>jms.queue.selectorQueue</address>
<filter string="color='red'"/>
</queue>
</queues>
</code></pre>
<p>Once configured the queue 'selectorQueue' only delivers messages that are selected against the filter, i.e.,
only the messages whose 'color' properties are of 'red' values can be received by its consumers. Those that don't match
the filter will be dropped by the queue and therefore will never be delivered to any of its consumers.</p>
<p>In the example code, five messages with different 'color' property values are sent to queue 'selectorQueue'. One consumer
is created to receive messages from the queue. Of the five sent messages, two are of 'red' color properties, one is 'blue',
one is 'green' and one has not the 'color' property at all. The result is that the consumer only gets the two 'red' messages.</p>
</body>
</html>