0

I am looking options to implement feature like Active MQ message groups in my application. This application is based on Spring and uses Websphere MQ as JMS provider. I cannot change JMS provider to ActiveMQ due to client constraints.

Use Case : Messages arrive in bulks on queue 1 where they are picked by listener and split into chunks and en-queued to the queue 2. Queue 2 has a single threaded listener which processes messages one after another but this behavior is leading to performance issues where there are too many messages on Queue 2. Also since bulk can have some related messages i.e. Object Create and Object Update, simply having parallel consumers wont solve the problem. As messages need to be grouped based on order Id (or some other)attribute and then this group needs to be processed by exclusive consumer.

I cant find any feature in MQ or Spring JMS to implement this unlike Message Groups provided by Active MQ.

  • This answer I provided gives information on how to send group messages from JMS: "[How to implement Logical ordering in IBM MQ in Java?](https://stackoverflow.com/questions/46242936/how-to-implement-logical-ordering-in-ibm-mq-in-java/46245234#46245234)". The Article that has been taken down that I referenced also shows how to receive group messages, you may be able to get this from Google cache. I have no heard back from the author on getting it republished. – JoshMc Nov 16 '17 at 18:42
  • Thanks. Glad to know that option like this exists. However since in my use case i cannot group the items upfront before processing as updates can arrive at any point of time, problem wont resolve. Above solution needs me to define the end of the group which is not possible as I can expect message for group to arrive at any time. – Vaibhav Chavan Nov 17 '17 at 14:46
  • When you put the message to Queue 2 you could set a message property that is unique to each group of messages, your consumers on Queue 2 can consume with a selectors based on that property and value. For sending a message with a property set look at "[Not seeing message properties that I set explicitly (Spring/JMS/MQ)](https://stackoverflow.com/questions/7642206)". For consuming by selector look at Shashi's answer about how to do this with the JMS API on "[How do you set a message selector using Java API?](https://stackoverflow.com/questions/29016024)" – JoshMc Nov 18 '17 at 04:07
  • Thanks Again and sorry for coming back late on this. Problem here is my process is expected to be Asynchronous and based on what I understand I can not use selectors with Listeners ? – Vaibhav Chavan Nov 27 '17 at 12:41
  • In the IBM White paper by Angel Rivera "[Using an MDB with JMS message selectors with WebSphere MQ V7.x and WebSphere Application Server V7 and V8.x](http://www-01.ibm.com/support/docview.wss?uid=swg27016581)" describes how to setup MDBs with selectors. – JoshMc Nov 27 '17 at 14:43
  • Problem i see with this approach is, it expects to ignore a message which does not match with selector string. In my case, I cannot afford to ignore the messages. Also I may not like the idea of enqueing them again. At our end we have solved this requirement by applying a workaround. Since we use gemfire, we have utilized DistributedLockService feature wherein we lock the Key which we consider as Group Id when a message is under processing. When there is some other message belonging to same group gets picked up by another listener, it waits until it acquires a lock. – Vaibhav Chavan Nov 28 '17 at 14:55
  • The setup I suggested would be that you have multiple listeners one for each expected selector string. While one listener may ignore messages that it is not interested in there should be another listener that is interested in those messages. – JoshMc Nov 28 '17 at 15:14

0 Answers0