Search

26.3.  Clustered Grouping

download PDF
Using message groups in a cluster is a bit more complex because messages with a particular group ID can arrive on any node. Each node needs to know which group IDs are bound to which consumer on which node.
The consumer handling messages for a particular group ID may be on a different node of the cluster, so each node needs to know this information so it can route the message correctly to the node which has that consumer.
To solve this there is a grouping handler. Each node has its own grouping handler and when a message is sent with a group ID assigned, the handlers will decide between them which route the message should take.
There are two types of handlers; local and remote. Each cluster should choose one node to have a local grouping handler and all the other nodes should have remote handlers. The Local handler makes the decision regarding what route to use. The remote handlers converse with this. Here is a sample configuration for both types of handler. This should be configured in the <JBOSS_HOME>/jboss-as/server/<PROFILE>/deploy/hornetq/hornetq-configuration.xml file.
<grouping-handler name="my-grouping-handler">
   <type>LOCAL</type>
   <address>jms</address>
   <timeout>5000</timeout>
</grouping-handler>
<grouping-handler name="my-grouping-handler">
   <type>REMOTE</type>
   <address>jms</address>
   <timeout>5000</timeout>
</grouping-handler>
The address attribute refers to a cluster connection and the type of addressing it uses (jms, or core). The timeout attribute refers to how long to wait for a decision to be made (in milliseconds); an exception will be thrown during the send if this timeout is reached. This ensures that strict ordering is kept.

Note

Refer to Chapter 36, Clusters for information about configuring clusters.
The decision about where a message should be routed is initially proposed by the node that receives the message. The node will pick a suitable route as per the normal clustered routing conditions (that is, circulate available queues, use a local queue first, and choose a queue that has a consumer). If the proposal is accepted by the grouping handlers, the node will route messages to this queue from that point on. If rejected an alternative route will be offered and the node will route to that queue indefinitely. All other nodes will also route to the queue chosen at proposal time. Once the message arrives at the queue, normal single-server message group semantics take over and the message is attached to a consumer on that queue.
You may have noticed that there is a single point of failure with the single local handler. If this node crashes then no decisions will be able to be made. Any sent messages will be not be delivered and an exception will be thrown. To avoid this happening, local handlers can be replicated on another backup node. Simple create your back up node and configure it with the same local handler.

26.3.1. Clustered Grouping Best Practices

Some best practices should be followed when using clustered grouping:
  1. Make sure your consumers are distributed evenly across the different nodes if possible. This is only an issue if you are creating and closing consumers regularly. Since messages are always routed to the same queue once pinned, removing a consumer from this queue may leave it with no consumers, meaning the queue will just keep receiving the messages. Avoid closing consumers or make sure that you always have plenty of consumers, that is, if you have three nodes, have three consumers.
  2. Use durable queues if possible. If queues are removed once a group is bound to it, then it is possible that other nodes may still try to route messages to it. This can be avoided by making sure that the queue is deleted by the session that is sending the messages. This means that when the next message is sent it is sent to the node where the queue was deleted meaning a new proposal can successfully take place. Alternatively you could just start using a different group id.
  3. Always make sure that the node that has the local grouping handler is replicated. This means that grouping can still occur on fail-over.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.