MessageGroups with Spring and Websphere MQ - ibm-mq

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.

Related

Retry Interval in IBM MQ Queues

We have JMS Listeners implemented in Spring which are listening to a Queues created on IBM MQ. Since we have multiple resources e.g. MQ, Database we are using JTA transaction manager which in case of transaction rollbacks puts message back on queue. Though we could configure retry count using back-out threshold property of queue, i could not find anything that lets us configure retry interval. Do you have any experience implementing the same ? if no direct solution any workaround which can be easily applied ?

How does a Topic Message Driven Bean behave in Websphere 8.5.5 Cluster Environment

What I would like is to run a Message Driven Bean that listens onto a (Websphere MQ7) topic. I would like to deploy my application on a Websphere 8.5.5 Cluster containing two cluster members.
If a message for the topic arrives I would expect that only one of my two MDBs gets the message and process it.
IBM states that I should set identically ClientIds and Subscription Names to ensure that only one instance is able to process a message on a Topic:
http://www-01.ibm.com/support/docview.wss?uid=swg21442559
Will the second MDB receive the mentioned MQRC_SUBSCRIPTION_IN_USE Exception, or will the cluster take care that one and only one MDB in the cluster will consume the topic-message?
Maybe someone can point me to the IBM Documentation where this behaviour is defined.
To allow multiple concurrent instances of an MDB to access the same subscription on an MQ queue manager you can enable "Allow cloned durable subscriptions" in the activation spec for the MDB.
https://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/umj_pasm.html
Running like this means both instances of the MDB will start (no IN_USE errors) and each message for that single subscription will be processed by one instance of the MDB. You would use this to workload balance messages across the multiple WAS servers.
This is only true for durable subscriptions. And only when the MDB instances are connected to the same queue manager.

What does Spring JMS ActiveMQ use to determine when a broker should switch Exclusive Consumers?

An exclusive consumer in Activemq is one that is sent every message from a broker until the consumer dies or goes away, at which time the broker switches consumer.
What is it that defines when the switchover takes place? How do you configure this in Spring JMS/ActiveMQ?
It's not Spring JMS doing the checking; it's the JMS provider, ActiveMQ.
JMS is an API specification; an empty framework, essentially. ActiveMQ provides the implementation backing for managing connections, message brokering, load-balancing, fail-over, etc.
The ActiveMQ broker handles switching-over consumers based on queue properties (you don't need to do anything special in your code):
queue = new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true");
The switch-over takes place when either the consumer disconnects gracefully or the broker determines that the consumer has disappeared (via the wireFormat.maxInactivityDuration elapsing without any messages or keep-alives being received). You don't have to configure anything if you're happy with the default value of wireFormat.maxInactivityDuration (30 seconds), but you can tweak that if you want to change how long it takes before the broker gives up on a client.

Websphere equivalent for Weblogic bridge level message filter

In weblogic it is possible to create a message bridge between two JMS message queues. While configuring this bridge, a message filter can be applied so that the bridge will route messages that match the filter only.
Is it possible to achieve the same with Websphere?
Specifically I'm trying to achieve this scenario.
I have one source queue on which messages are received. Each message will have a custom JMS property set up. I would like to forward the messages on the source queue, to separate queues based on the JMS property and its value. This is easily configured in WLS using message bridges with filtering. How can I do the same in WAS?
Thanks
Savio
You need to use SIB Mediation.
The WAS info center have an example called writing a routing mediation which seems like what you need.
At the bottom of the example there is a link to what to do next which also explains how to configure WAS to use that mediation.
Without writing custom code (as per your comment on Aviram's answer), it is not possible to achieve the exact same thing, but nonetheless it is possible to achieve same effect;
You say that a 'source queue' distributes messages to other 'separate queues' according to a custom JMS property. I'm assume that you have MDBs (message driven beans) configured to process messages in these separate queues.
What you can do with WebSphere is distribute messages to these MDBs directly from the 'source queue', without having to filter/distribute them to separate queues.
This is managed by using JMS Message Selectors. You can point all your MDBs to the source queue using activation specification definitions, and for each (one for each type of message) MDB, define a JMS Message Selector that matches the ones you use in WLS. This way each message is only delivered the MDB whose filter matches the message's properties. This effectively filters/distributes messages to different MDB's as in WLS.
You may read details on configuring message selectors (during development in RAD, or at/after deploy time) at infocenter. Below is a quote to give you an idea about what it look like;
messageSelector
This attribute determines the JMS message selector
that is used to select which messages the message-driven bean
receives. For example:
JMSType='car' AND color='blue' AND weight>2500
The selector string can refer to fields in the JMS message header and
fields in the message properties. Message selectors cannot reference
message body values.
For the record, we finally ended up writing our own routing algorithm within the application to ensure that messages are sent to separate queues for each client. This way we are independent of app server implementations and the integration effort is the same across app servers, viz., adding custom queues per integrating client.
In brief, We published a JMS custom property that must be set. Using a published convention, we look up for a queue and send responses to the queue. If the property is not set, a default queue is created to route all messages. If the property is set, and the queue cannot be found an exception is raised and processing halted.
This suited our purpose. Hope it helps...

How to receive multiple messages from an IBM MQ

I'm connecting to an IBM Websphere MQ and currently reading one message at a time using the method receive() from the object:
javax.jms.Message;
Is there a way to retrieve multiple messages from the queue in one go?
Many thanks,
G.
Depends on whether you make a distinction between "read" and "retrieve".
From a JMS perspective, no. The API will return one message per method call.
From the WMQ perspective, yes - provided the client and queue manager are both at v7 and the messages are non-persistent or being browsed. In this case you can enable read-ahead in the managed object definition or dynamically at run time. The queue manager will stream several messages off of the queue and deliver them to the application before the first one is acknowledged. For more information on this, see Using read ahead with WebSphere MQ classes for JMS.

Resources