Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JMS to connect to IBM MQ

Tags:

jms

ibm-mq

I want to use JMS to connect to IBM MQ. How do i specify the queuemanager, the channel and other properties ?

like image 222
Anand Sunderraman Avatar asked Feb 24 '10 06:02

Anand Sunderraman


People also ask

Does IBM MQ use JMS?

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.

How do I connect to IBM MQ from Java application?

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.


2 Answers

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
like image 165
Ahmad Y. Saleh Avatar answered Oct 03 '22 22:10

Ahmad Y. Saleh


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>
like image 43
Piyush Verma Avatar answered Oct 04 '22 00:10

Piyush Verma