9.2. How to Enable Message Ordering Group
You can enable an ordering group either on a connection factory or on a producer:
- If you define the ordering group on a connection factory, all producers on the connection factory use the same ordering group (refer to Section 9.2.1, “Enabling Ordering Group on Producer”).
- If you define the ordering group on a producer (note that the producer is defined on a connection factory), the producer uses the defined ordering group. If the connection factory of the producer defines an ordering group as well, the producer ordering group overrides the setting and uses its own ordering group (refer to Section 9.2.2, “Enabling Ordering Group on Connection Factory”).
9.2.1. Enabling Ordering Group on Producer
To enable the ordering group feature on producer, do the following:
- Add a
JBossMessageProducer
to your session:JBossMessageProducer producer=(JBossMessageProducer)session.createProducer(queue);
- Add the enableOrderingGroup method to set an ordering group:
producer.enableOrderingGroup(String ogrpName) throws JMSException
The method creates an ordering group; when the method is called, JBossMessageProducer sends messages on behalf of the ordering group. If you providenull
as the method parameter, the ordering group is generated automatically. A new call to this method overrides the previous call. - Optionally, you can add the
disableOrderingGroup()
method to disable the ordering group:public void disableOrderingGroup() throws JMSException
When the method is called, JBossMessageProducer stops sending ordering group messages and resumes its default behavior.
An example is available in
$EAPHOME/doc/examples/jboss-messaging-examples/ordering-group/
in the class OrderingGroupExample.java
(src/org/jboss/example/jms/ordering/OrderingGroupExample.java
). Note that the example is delivered as part of the jboss-eap-docs
archive.