<p>By default, Message counter is not enabled (for performance reason). To enable them, set <code>message-counter-enabled</code> to <code>true</code>.<br/>
Queues are sampled every 10 seconds by default. For this example we will reduce it to 2 seconds by setting <code>message-counter-sample-period</code> to <code>2000</code>.<br/>
ActiveMQ Artemis holds in memory the message counters' history for a maximum number of days (10 by default). We can change the number of days the history is kept by setting
<p>The sample period and the max day history parameters have an small impact on the performance of ActiveMQ Artemis (the resources taken to sample a queue are not available to the system's
<li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
<li>We will now sleep a little bit to be sure the queue is sample. Since we have configure the sample period to be 2 seconds,
we will sleep for 3 seconds to be sure that a sample is taken</li>
<preclass="prettyprint">
<code>System.out.println("Sleep a little bit to have the queue sampled...");
Thread.sleep(3000);</code>
</pre>
<p>We now need to retrieve the message counters. They're available from the JMS Queue management resource. In this example, we
will retrieve them using JMX (see the <ahref="../jmx/readme.html">JMX example</a> for a more complete description). You can also use JMS message to retrieve them (see the <ahref="../management/readme.html">Management example</a> to
<li>We retrieve the message counter and display them. MessageCounters are retrieved as <code>JSON Strings</code> for portability reason (whether
JMX is used for management or JMS messages). To make it simpler to use them in the code, there is a <code>MessageCounterInfo</code> data structure.</li>
<p>The message counter contains a variety of metrics on the queue which is sampled (total messages added to the queue, current depth of the queue, deltas since the last sample, timestamp
of the last message added, timestamp of the last sample, etc.)</p>
<li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>