简体   繁体   English

使用JMS连接到IBM MQ

[英]Using JMS to connect to IBM MQ

I want to use JMS to connect to IBM MQ. 我想使用JMS连接到IBM MQ。 How do i specify the queuemanager, the channel and other properties ? 如何指定queuemanager,channel和其他属性?

Using JNDI for connectionFactory/destinations lookups, provide the InitialContext with the following properties: 使用JNDI进行connectionFactory / destinations查找,为InitialContext提供以下属性:

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: 使用WAS(Websphere Application Server)队列,属性如下:

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. 您需要创建MQQueueConnectionFactory bean并在其中设置所需的属性。

<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>

Using IBM client API 使用IBM客户端API

            import com.ibm.mq.MQEnvironment;
            import com.ibm.mq.MQQueue;
            import com.ibm.mq.MQQueueManager;
            import com.ibm.mq.constants.CMQC;

            public class QueueMonitoring {

                public static void main(String[] args) {
                    int openOptions = CMQC.MQOO_INQUIRE | CMQC.MQOO_INPUT_AS_Q_DEF;
                    MQEnvironment.hostname = "192.168.59.103";
                    MQEnvironment.port = 1414;
                    MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
                    MQEnvironment.properties.put(CMQC.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES);

                    MQQueueManager qMgr;
                    try {
                        qMgr = new MQQueueManager("QM1");
                        MQQueue destQueue = qMgr.accessQueue("DOCKERQ", openOptions);
                        System.out.println("Queue size:" + destQueue.getCurrentDepth());
                        destQueue.close();
                        qMgr.disconnect();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                }

Here's a tutorial that may help: 这是一个可能有用的教程

Also, be sure to use the docs for the right version of WMQ. 此外,请务必使用适用于WMQ版本的文档。 V7.0 is current and v6.0 is supported until September 2011. Whichever you are using, look at the Using Java manual for the right version: V7.0是最新的,v6.0支持到2011年9月。无论您使用哪种,请查看正确版本的Using Java手册:

v6.0 manual v6.0手册
v7.0 manual v7.0手册

the best way is to use the command line. 最好的方法是使用命令行。 It is a lot of fun. 太有趣了。 You could download the command reference book from http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/csqzaj05.pdf 您可以从http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/csqzaj05.pdf下载命令参考手册。

If your MQ server is running on a windows machine, you could optionally use a MQExplorer and configure it graphically. 如果您的MQ服务器在Windows机器上运行,您可以选择使用MQExplorer并以图形方式对其进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM