Currently, I am using javax.jms.ConnectionFactory with Apache Camel and Spring Boot for messaging. I want to use connection pool for connecting IBM MQ in Spring bean. How can I do that?
-
Review this question where it shows use of the spring `CachingConnectionFactory`: [Java Spring JMS: JmsTemplate to IBM MQ](https://stackoverflow.com/questions/42356712/java-spring-jms-jmstemplate-to-ibm-mq) – JoshMc Nov 20 '18 at 17:37
1 Answers
On the IBM MQ server there should be a java/lib
folder containing the JAR files you need for connecting to IBM MQ, as is being mentioned within the IBM Knowledge Center:
Within an enterprise, the following files can be moved to systems that need to run IBM MQ classes for Java applications:
- com.ibm.mq.allclient.jar
- com.ibm.mq.traceControl.jar
The file
com.ibm.mq.allclient.jar
contains the IBM MQ classes for JMS, the IBM MQ classes for Java, and the PCF and Headers Classes. If you move this file to a new location, make sure that you take steps to keep this new location maintained with new IBM MQ Fix Packs. Also, make sure that the use of this file is made known to IBM Support if you are getting an interim fix.
Within these JAR files, you can find an implementation of ConnectionFactory
, called MQQueueConnectionFactory
. You have to add the necessary JAR files to the classpath of your application, and then you can configure the ConnectionFactory
, for example:
@Bean
public ConnectionFactory ibmConnectionFactory() throws JMSException {
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
// Change this to the hostname of the IBM MQ server
connectionFactory.setHostName("myhost.example.org");
connectionFactory.setPort(1414);
// Change this to the queue manager you use
connectionFactory.setQueueManager("MQ_NAME");
connectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
// Create your own channel in stead of using SYSTEM.DEF.SVRCONN
connectionFactory.setChannel("SYSTEM.DEF.SVRCONN");
return connectionFactory;
}

- 1
- 1

- 41,995
- 13
- 95
- 133
-
-
1Everything in the connectionFactory. Also, don't use the SYSTEM.DEF.SVRCONN channel. Have the MQAdmin create a unique channel for your application. – Roger Nov 20 '18 at 16:02
-
I think the question is more about how to configure MQ connection pool in spring boot. But this answer describes how to create MQ connection factory instead. – Rajib Biswas Jul 18 '23 at 11:45
-
@RajibBiswas I'm not sure what you mean by that. A `ConnectionFactory` bean is used as the factory for creating connections in the MQ connection pool, so I would think this suffices. – g00glen00b Jul 18 '23 at 12:44