Message groups in WebSphere MQ

I have a requirement that I need to process JMS messages (via MDB) so that messages belonging to a specific group (group identifier) ​​are consumed by the same bean instance. The behavior that I need in this case is that messages with the same group identifier are processed sequentially (although the order of messages does not matter), and binding them to the same MDB instance should provide this.

Messages do not contain any sequence number (since this does not matter), and we do not know what the first or last message in the group is (theoretically, "never" was the last message in the group). We want them to be delivered as soon as the consumer can receive them.

ActiveMQ provides this exact function ( http://activemq.apache.org/message-groups.html ) by simply setting the JMSXGroupID. However, we are associated with WebSphere MQ. All that I have found out so far is that you can collect messages of the same group in the queue and use MessageSelector to receive the message "Last message in the group", as described at http://www.ibm.com/developerworks/ websphere / library / techarticles / 0602_currie / 0602_currie.html . We would prefer a cleaner method (for example, in ActiveMQ). Does anyone know how to achieve this behavior in WebSphere?

Thanks!

+7
source share
1 answer

Typically, you use MessageSelectors in implementations of IBM JMS products (both for the implementation of WebSphere MQ and SIBus). This is the equivalent of a filter that scans an HTTP or SOAP message header for web protocols.

Although this may not be what you want, it is actually a clean and thoughtful design.

However, if you do not want to use MessageSelectors, you probably have to create your own and β€œprocess” the message using the built-in MDB, which scans the headers and then forwards the message to the appropriate queue, where only the MDB that takes care of the grouped messages will process them (like a gateway / message selection pattern).

If you use a "pure" JMS API, you can ask the Session object to create a MessageConsumer with the specified selector string (the value in the header) that you want to filter (again you need to set this yourself).

//assume we have created a JMS Connection and Session object already. //and looked up the Queue we want already. MessageConsumer consumerWithSelector = session.createConsumer(queue, groupId); 

This is all that gives you a clean JMS API. Everything else depends only on the developer of the messaging technology, which is then patented for their implementation, and not portable code.

+2
source

All Articles