<p>Message groups are sets of messages that has the following characteristics: </p>
<li>Messages in a message group share the same group id, i.e. they have same JMSXGroupID string property values.</li>
<li>Messages in a message group will be all delivered to no more than one of the queue's consumers. The consumer that receives the
first message of a group will receive all the messages that belongs to the group.</li>
<p>You can make any message belong to a message group by setting a 'group-id' on the connection factory. All producers created via this connection factory will set that group id on its messages.
In this example we set the group id 'Group-0'on a connection factory and send messages via 2 different producers and check that only 1 consumer receives them. </p>
<p>Alternatively, ActiveMQ's connection factories can be configured to <em>auto group</em> messages. By setting <code>autogroup</code> to </code>true</code> on the <code>ActiveMQConnectionFactory</code>
will be picked to create a message group. <em>Every messages</em> sent by a producer created from this connection factory will automatically
be part of this message group.</p>
<h2>Example step-by-step</h2>
<p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>
<ol>
<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>
System.out.println("Group message [producer2 message " + i + "] went to wrong receiver: " + receiver);
result = false;
}
}
</code>
</pre>
<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>