如何将Java JMS与MQseries结合使用 [英] How to use Java JMS with MQseries

查看:116
本文介绍了如何将Java JMS与MQseries结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发JMS 独立应用程序,以读取和写入MQSeries上的队列. 我的老板要求我使用纯Java JMS (不是ibm.mq库)来完成该操作.

I am trying to develop a JMS standalone application to read and write to a Queue on MQSeries. My boss asked me to use pure java JMS (not ibm.mq lib) to do that.

以下是建立jms连接所需的信息:

Here is the information that need to make the jms connection:

  mq.hostname=10.10.10.10
  mq.channel=API.CLIENTCHL
  mq.queueManager=MQPETAPI
  mq.port=1422

您知道该怎么做吗,或者您有任何链接教我做到这一点.

Do you know how to do that Or do you have any link that teach me to do that.

推荐答案

这里的问题是我的老板要求我使用纯Java JMS(而不是ibm.mq lib)来执行此操作". JMS是一个规范,每个实现都必须遵守API和语义,但是可以自由地在底层进行任何所需的操作.始终有必要使用运输供应商提供的实现类.因此,如果将WebSphere MQ用作传输工具,则需要使用IBM MQ JMS类来编写JMS应用程序.

The issue here is the requirement that "My boss asked me to use pure java JMS (not ibm.mq lib) to do that." JMS is a specification and each implementation must comply with the API and the semantics, but is free to do whatever they want at a low level. It is always necessary to use the implementation classes provided by the transport vendor. Therefore if you use WebSphere MQ as the transport, you will need to use the IBM MQ JMS classes to write a JMS application.

也就是说,如果您坚持使用纯JMS API调用,则可以插入任何传输供应商的类.这是给您提供原始帖子中提到的要求时通常所希望的.

That said, if you stick with pure JMS API calls you would be able to plug in any transport vendor's classes. This is what is usually intended when you are given requirements such as that mentioned in the original post.

有一篇文章准确地描述了您的工作,名为 运行独立的Java WebSphere MQ V6.0上的应用程序 它仅使用JMS API,并且在本地文件系统(.bindings文件)中使用JNDI.通过将IBM JMS类换成其他供应商并使用其JNDI工具,您将能够插入任何JMS传输,而无需使用这种方法更改代码.

There's an article describing exactly what you are looking to do called Running a standalone Java application on WebSphere MQ V6.0 It uses only the JMS API and it uses JNDI in a local file system (a .bindings file). By swapping out the IBM JMS classes for another vendor and using their JNDI tools you would be able to plug in any JMS transport without changing your code using this approach.

如果要在没有JNDI的情况下执行相同的操作,请查看MQ客户端安装随附的示例程序,您在其中获得了Java类.在UNIX/Linux系统中,它们在/opt/mqm/samp中,而在Windows中,它们在install_dir/tools/jms/samples中. SimpleRequestor.java示例包含以下代码,用于在不使用JNDI的情况下初始化连接工厂:

If you want to do the same thing without JNDI, look at the sample programs provided with the MQ client install where you obtained your Java classes. In a UNIX/Linux system these are in /opt/mqm/samp and on Windows they are in install_dir/tools/jms/samples. The SimpleRequestor.java sample has the following code for initializing your connection factory without JNDI:

try {
  // Create a connection factory
  JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
  JmsConnectionFactory cf = ff.createConnectionFactory();

  // Set the properties
  cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "localhost");
  cf.setIntProperty(WMQConstants.WMQ_PORT, 1414);
  cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "SYSTEM.DEF.SVRCONN");
  cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
  cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "QM1");

由于此方法不使用JNDI,因此您需要编写不可在传输供应商之间传输的代码.它是特定于IBM WebSphere MQ的.

Because this approach does not use JNDI, you are required to write code that is not transportable across transport vendors. It is IBM WebSphere MQ specific.

如果您是从某个地方拿起MQ jar的,并且没有完整安装(因此没有样本),则可以将其下载为SupportPac MQC7 .该下载是免费的.通常,即使使用后级队列管理器,也应使用最新的客户端.显然,您没有从V6 QMgr获得V7功能,但是即使对于V6功能,V7客户端中的JMS实现也有了很大的改进.如果出于某些原因您确实必须使用V6客户端,则可以将其下载为

If you grabbed the MQ jars from somewhere and do not have the full install (and thus do not have the samples) you can download it as SupportPac MQC7. The download is free. In general you should use the latest client, even with a back-level queue manager. Obviously you do not get V7 functionality from a V6 QMgr but the JMS implementation in the V7 client is much improved, even for V6 functionality. If for some reason you really must use the V6 client, you can download it as SupportPacMQC6. Whichever client version you use, make sure to use the corresponding Infocenter.

V6信息中心
V7信息中心

最后,带有所有SupportPacs索引的登录页面为这里.

Finally, the landing page with an index for all the SupportPacs is here.

这篇关于如何将Java JMS与MQseries结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆