Using client connections to connect to multiple IBM MQ queue managers
You can configure client connected applications to connect to more than one queue manager (for load balancing or service availability reasons).
The primary mechanisms to achieve this in the IBM® MQ client are use of client channel definition tables, see Configuring client channel definition tables, or connection lists.
It is also possible to achieve similar behavior using external load balancing products or by wrapping IBM MQ connection code in a 'stub' which can redirect host names or IP addresses.
Each of these techniques comes with some restrictions, and might be more or less suitable to particular application requirements. The following sections, although not exhaustive, describe particular aspects you should consider, and the effect of these different approaches on these aspects.
IBM MQ uniform clusters (see About uniform clusters) provide a powerful mechanism to achieve horizontal scaling of applications across multiple queue managers, building on the basic mechanism of the CCDT to provide multiple destinations. Uniform clusters can provide capabilities beyond what is possible by using an external load balancer that is unaware of the underlying IBM MQ protocols, and avoid some of the problems discussed later in this topic, so consider using a uniform cluster in preference to other techniques where applicable.
- Applications that make multiple connections to the queue manager. Such applications include any that use IBM MQ classes for JMS or IBM MQ classes for Jakarta Messaging because these classes create multiple IBM MQ connections in general usage. If you use an external load balancer or custom code stub, it must always route connections from the same application instance to the same queue manager.
- Applications that use XA transaction management or the Java Transaction API (JTA). Such applications must always connect or reconnect consistently to the same queue manager. If the load balancing technology that you are using cannot ensure this consistency, you cannot use XA or JTA reliably.
- Uniform cluster application balancing. This feature relies on being able to instruct clients to reconnect to specific queue managers without interference. So, it is not advisable to attempt to combine external load balancing with the use of uniform clusters
Where possible, consider using IBM MQ uniform clusters instead of external load balancing technologies.
Terms used in this information
- CCDT- multi-QMGR
- Means a CCDT file that contains multiple client connection (CLNTCONN) channels with the same group, that is the queue manager name client connection (QMNAME CLNTCONN) attribute, where different CLNTCONN entries resolve to different queue managers.
- Load balancer
- Means a network appliance with a Virtual IP address (VIP) configured with port monitoring of the TCP/IP listeners of multiple IBM MQ queue managers. How the VIP is configured in the network appliance depends on the network appliance you are using.
The following choices relate only to applications sending messages, or initiating synchronous request and reply messaging. The considerations for applications servicing those messages and requests, for example, the listeners are completely separate, and discussed in detail in "Connecting a message listener to a queue".
Scale of code change required for existing applications that connect to a single queue manager
- CONNAME list, CCDT multi-QMGR, and Load balancer
- MQCONN("QMNAME") to MQCONN("*QMNAME")
- Code stub
- Replace existing JMS or MQI connection logic with a code stub.
Support for different WLM strategies
- CONNAME list
- Prioritized only.
- CCDT multi-QMGR
- Prioritized or random.
- Load balancer
- Any, including each connection for all messages.
- Code stub
- Any, including each message for all messages.
Performance overhead while primary queue manager is unavailable
- CONNAME list
- Always tries first in list.
- CCDT multi-QMGR
- Remembers last good connection.
- Load balancer
- Port monitoring avoids bad queue managers.
- Code stub
- Can remember last good connection, and retry intelligently.
XA transaction support
- CONNAME list, CCDT multi-QMGR, and Load balancer
- The transaction manager needs to store recovery information that reconnects to the same queue manager resource.
- Code stub
- Code stub can meet the XA requirements for a transaction manager, for example, multiple connection factories.
Admin flexibility to hide infrastructure changes from apps
- CONNAME list
- DNS only.
- CCDT multi-QMGR
- DNS and shared file-system, or shared file-system, or CCDT file push.
- Load balancer
- Dynamic virtual IP address (VIP).
- Code stub
- DNS or single queue manager CCDT entries.
Avoiding disruption around planned maintenance
There is another situation that you need to consider and plan for, which is how to avoid disruption to applications, for example, errors and timeouts visible to the end users, during planned maintenance of a queue manager. The best approach to avoid disruption is to remove all work from a queue manager before it is stopped.
Consider a request and reply scenario. You want all in-flight requests to complete, and the replies to be processed by the application, but you do not want any additional work to be submitted into the system. Simply quiescing the queue manager does not fulfill this need, as well-coded applications receive a return code RC2161 MQRC_Q_MGR_QUIESCING exception, before they receive their reply messages for in-flight requests.
You can set PUT(DISABLED) on the request queues used to submit work, while leaving the reply queues both PUT(ENABLED) and GET(ENABLED). In this way, you can monitor the depth of the request, transmission, and reply queues. Once they all stabilize, that is, in-flight requests complete or time out, you can stop the queue manager.
However, good coding in the requesting applications is required to handle a PUT(DISABLED) request queue, which results in the return code RC2051 MQRC_PUT_INHIBITED error, when trying to send a message.
Note that the exception does not occur when creating the connection to IBM MQ, or opening the request queue. The exception occurs only when an attempt is made to actually send a message, using the MQPUT call.
Building a code stub that includes this error handling logic for request and reply scenarios, and asking your application teams to use such a code stub in the future, can help you develop applications with consistent behavior.