使用 JMS 连接到 IBM MQ

发布于 2024-08-22 22:31:04 字数 46 浏览 5 评论 0原文

我想使用 JMS 连接到 IBM MQ。 如何指定队列管理器、通道和其他属性?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏见 2024-08-29 22:31:04

使用 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=

使用 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=

其余的如下:

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

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
染柒℉ 2024-08-29 22:31:04

您需要创建一个 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>

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>
瞎闹 2024-08-29 22:31:04

这里的教程可能会有所帮助:

此外,请务必使用正确版本的 WMQ 的文档。 V7.0 是最新版本,v6.0 的支持截止到 2011 年 9 月。无论您使用哪一个,请查看《使用 Java》手册以获取正确的版本:

v6.0 手册
v7.0 手册

Here's a tutorial that may help:

Also, be sure to use the docs for the right version of 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:

v6.0 manual
v7.0 manual

趁微风不噪 2024-08-29 22:31:04

使用 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();
                    }

                }
                }

Using IBM client 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();
                    }

                }
                }
晚雾 2024-08-29 22:31:04

最好的方法是使用命令行。这很有趣。您可以从 http://publib 下载命令参考书。 boulder.ibm.com/iseries/v5r2/ic2924/books/csqzaj05.pdf

如果您的 MQ 服务器在 Windows 计算机上运行,​​您可以选择使用 MQExplorer 并以图形方式配置它。

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

If your MQ server is running on a windows machine, you could optionally use a MQExplorer and configure it graphically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文