<!--
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 Message Expiration 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>JMS Expiration 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 ActiveMQ Artemis so messages are expipired after a certain time.</p>
<p>Messages can be retained in the messaging system for a limited period of time before being removed.
JMS specification states that clients should not receive messages that have been expired (but it does not guarantee this will not happen).</p>
<p>ActiveMQ Artemis can assign a <em>expiry address</em> to a given queue so that when messages are expired, they are removed from the queue and
routed to this address. These "expired" messages can later be consumed for further inspection.
<p>
The example will send 1 message with a short <em>time-to-live</em> to a queue. We will wait for the message to expire and checks that the message
is no longer in the queue it was sent to.
We will instead consume it from an <em>expiry queue</em> where it was moved when it expired.
</p>
<h2>Example setup</h2>
<p>Expiry destinations are defined in the configuration file <a href="server0/broker.xml">broker.xml</a>:</p>
<pre class="prettyprint">
<code><address-setting match="jms.queue.exampleQueue">
<expiry-address>jms.queue.expiryQueue</expiry-address>
</address-setting>
</code>
</pre>
<p>This configuration will moved expired messages from the <code>exampleQueue</code> to the <code>expiryQueue</code></p>
<p>ActiveMQ Artemis allows to specify either a <code>Queue</code> by prefixing the <code>expiry-address</code> with <code>jms.queue.</code>
or a <code>Topic</code> by prefixing with <code>jms.topic.</code>.<br />
In this example, we will use a <code>Queue</code> to hold the expired messages.</p>
<p>Since we want to consume messages from this expiryQueue, we also need to add a JNDI binding to perform a lookup.
This is configured in <a href="server0/activemq-jms.xml">activemq-jms.xml</a></p>
<pre class="prettyprint">
<code><queue name="expiryQueue">
<entry name="/queue/expiryQueue"/>
</queue></code>
</pre>
</body>
</html>