Let's say there is an order processing grid on 10 nodes, each of which needs to load customer account data into a cache. Each node can hold 10% of the customer data. Every node subscribes to the "ORDERS" queue at the broker. When the producer to the ORDERS queue produces a message, it sets the customer ID in the JMSXGroupID header. If the broker sees that this ID is unallocated, it selects a consumer from the 10 on the queue and delivers the message to it. Now ALL future messages with that ID will go to the same consumer which means it goes to the consumer with that account in its cache. This happens forever unless the consumer goes away. In that event, the broker will select a new consumer from the available ones the next time that account ID is seen in the JMSXGroupID header and that consumer will have to load the account data into cache.
Salient Features
- Messages in a message group share the same group id, i.e., they have the same group identifier property JMSXGroupID and an integer property to identify the group sequence.
- Messages in a message group are always consumed by the same consumer, even if there are many consumers in a queue. They pin all messages with the same group id to the same consumer. If that consumer is closed another consumer is chosen and will receive all messages with the same group id.
- A message group can be assigned to a different consumer by having the producer send a message which has "message group signal close", which is a boolean parameter, set to true. The same parameter can be used to indicate that the consumer handling this message group can be coupled with a different message group.