jmsspring-jms

JmsTemplate with CachingConnectionFactory & Load balancer


I am using Spring's JmsTemplate, CachingConnectionFactory, and JmsTransactionManager to commit or rollback sending messages to IBM MQ. I have multiple MQ hosts, and on top of it have a load balancer which can redirect the messages to any one of the MQ host.

I am establishing the connection using load balancer host. If I restart (gracefully/forcefully) any one of the MQ host behind the load balancer then what will happen to already established/cached connections? We don't want any message loss.


Solution

  • I'm not an expert with Spring or IBM MQ, but I've been working with JMS (mainly developing ActiveMQ) for a long time so I may be able to clarify things for you.

    JMS connections are stateful so once a connection is established to one of the MQ hosts then it will stay connected to that host until the host fails of the client closes the connection. This is in contrast to stateless connections for protocols like HTTP which often user load-balancers to scale up performance. Because of this load-balancers are not particularly useful with JMS.

    If you restart (gracefully/forcefully) any one of the MQ hosts behind the load-balancer then any established/cached connection to that host will be lost. Furthermore, any transaction in progress when the connection is lost will be rolled back. You should not lose any messages, but Spring will have to re-create the connection(s) and your application need to repeat any failed operations.