I want to use JMS to connect to IBM MQ. How do i specify the queuemanager, the channel and other properties ?
The JMS specification defines a set of interfaces that applications can use to perform messaging operations. From IBM MQ 8.0, the product supports the JMS 2.0 version of the JMS standard.
Client mode connection An IBM MQ classes for Java application can connect to any supported queue manager by using client mode. To connect to a queue manager in client mode, an IBM MQ classes for Java application can run on the same system on which the queue manager is running, or on a different system.
Using JNDI for connectionFactory/destinations lookups, provide the InitialContext
with the following properties:
java.naming.provider.url=<ip>:<port, default is 1414>/<channel name, default channel is SYSTEM.DEF.SVRCONN>
java.naming.factory.initial=com.ibm.mq.jms.context.WMQInitialContextFactory
java.naming.security.authentication=none
java.naming.security.credentials=
java.naming.security.principal=
using WAS (Websphere Application Server) queues, the properties would be as follows:
java.naming.provider.url=iiop://<ip>:<port, the defualt is 2809>
java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
java.naming.security.authentication=none
java.naming.security.credentials=
java.naming.security.principal=
The rest would be as follows:
Properties config = new Properties();
config.load(new FileInputStream("connectionConfig.properties"));// this file would contain the properties above
InitialContext context = new InitialContext(config);
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");// connection factory name
Destination destination = (Destination) context.lookup("destination");// queue/topic name
You need to create an MQQueueConnectionFactory bean and set the required properties in it.
<bean id="queueConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="transportType" ref="transport" />
<property name="queueManager" value="queueManagerName" />
<property name="hostName" value="hostName" />
<property name="port" value="portNumber" />
<property name="channel" value="channelName" />
</bean>
<bean id="transport"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
<property name="staticField">
<value>
com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP
</value>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With