Java 使用 JMS 访问 MQ

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3675883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 03:23:46  来源:igfitidea点击:

Accessing MQ with JMS

javajakarta-eejmsibm-mq

提问by hakish

i am using MQ7 and trying to access a queue with JMS api's. Getting this error. Has anyone seen it before? How do i resolve this? TIA

我正在使用 MQ7 并尝试使用 JMS api 访问队列。得到这个错误。有人见过吗?我如何解决这个问题?TIA

Exception in thread "main" com.ibm.msg.client.jms.DetailedJMSException: JMSFMQ6312: An exception occurred in the Java(tm) MQI. The Java(tm) MQI has thrown an exception describing the problem. See the linked exception for further information.

Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2495;AMQ8568: The native JNI library 'mqjbnd' was not found. [3=mqjbnd]

Caused by: java.lang.UnsatisfiedLinkError: no mqjbnd in java.library.path

线程“main”com.ibm.msg.client.jms.DetailedJMSException 中的异常:JMSFMQ6312:Java(tm) MQI 中发生异常。Java(tm) MQI 抛出了一个描述问题的异常。有关更多信息,请参阅链接的异常。

引起:com.ibm.mq.jmqi.JmqiException:CC=2;RC=2495;AMQ8568:未找到本机 JNI 库“mqjbnd”。[3=mqjbnd]

引起:java.lang.UnsatisfiedLinkError:java.library.path中没有mqjbnd

采纳答案by T.Rob

This is almost always caused by a combination of an incomplete client install and/or a CLASSPATH issue. Many people grab the jar files rather than performing the complete install and do not necessarily get all of them. In addition to insuring all required binaries are present, using the install media provides several additional capabilities such as diagnostics and trace. It also assures that maintenance can be applied. The WMQ client install media are available for free download as SupportPac MQC7. The CLASSPATH setting should be as described in the WebSphere MQ Using Javamanual.

这几乎总是由不完整的客户端安装和/或 CLASSPATH 问题的组合引起的。许多人获取 jar 文件而不是执行完整的安装,并且不一定获得所有这些文件。除了确保所有必需的二进制文件都存在之外,使用安装介质还提供了一些附加功能,例如诊断和跟踪。它还确保可以应用维护。WMQ 客户端安装介质可作为SupportPac MQC7免费下载。CLASSPATH 设置应如WebSphere MQ Using Java手册中所述。

If the client install is performed from the IBM media and the environment is set up as per the docs, this fixes nearly all cases such as you have reported here. There are a few Install Verification Test apps (some of those diagnostics installed with the full media that I mentioned) which are described hereand which can help determine if a problem is with the installation or with the code.

如果从 IBM 媒体执行客户端安装并且根据文档设置环境,这几乎可以解决所有情况,例如您在此处报告的情况。这里描述了一些安装验证测试应用程序(其中一些诊断程序与我提到的完整媒体一起安装)它们可以帮助确定问题是安装还是代码。

回答by Tomboy

The VM parameter -Djava.library.path=/opt/mqm/java/lib64works for me. My environment is 64bit Suse with MQ installed and my program is using 'Bindings' transport type

VM 参数-Djava.library.path=/opt/mqm/java/lib64对我有用。我的环境是安装了 MQ 的 64 位 Suse,我的程序正在使用“绑定”传输类型

回答by johnam

Probably a bit late but I had the same problem and found that this can be avoided if you use a different Connection Mode when connecting to a remote Queue. By default the MQConnectionFactoryuses WMQ_CM_BINDINGSas it's connection mode. If you change it to WMQ_CM_CLIENT(or whichever connection mode you like that doesn't require native libraries) you should be fine.

可能有点晚了,但我遇到了同样的问题,我发现如果在连接到远程队列时使用不同的连接模式可以避免这种情况。默认情况下,MQConnectionFactory使用WMQ_CM_BINDINGS它的连接模式。如果您将其更改为WMQ_CM_CLIENT(或您喜欢的任何不需要本机库的连接模式),您应该没问题。

@Test
public void testMQConnectionMode() throws JMSException {
    MQConnectionFactory cf = new MQConnectionFactory();
    assertThat(cf.getIntProperty(CommonConstants.WMQ_CONNECTION_MODE), is(equalTo(CommonConstants.WMQ_CM_BINDINGS)));
    cf.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
    assertThat(cf.getIntProperty(CommonConstants.WMQ_CONNECTION_MODE), is(equalTo(CommonConstants.WMQ_CM_CLIENT)));
}

回答by Imam Baihaqi

Agree with Johnam, it happened because the ConnectionFactory set as server by default, it need to be set as client, you said that it works on same machine. Because I also met the same situation, it run when on same machine, in this case because your machine is as WMQ Server so do the program, but when you run on different machine then your program must set as client.

同意Johnam,这是因为ConnectionFactory默认设置为服务器,需要设置为客户端,你说它在同一台机器上工作。因为我也遇到了同样的情况,在同一台机器上运行,这种情况下因为你的机器是WMQ Server所以程序也是这样,但是当你在不同的机器上运行时,你的程序必须设置为客户端。

I fix it using set some parameter on ConnectionFactory:

我使用在 ConnectionFactory 上设置一些参数来修复它:

<bean id="mqConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
....
<property name="transportType" value="1" />
<property name="clientReconnectTimeout" value="2" /> 
<property name="clientReconnectOptions" value="0" />
</bean>

回答by user5061020

The issue is with Path variable on system properties. Try to run code by specifying MQInstallation Dir :\Lib64 path before MQInstallation Dir :\Lib

问题在于系统属性上的 Path 变量。尝试通过在 MQInstallation Dir :\Lib 之前指定 MQInstallation Dir :\Lib64 路径来运行代码

回答by Venu Madhav

Add the below to your tomcat arguments:

将以下内容添加到您的 tomcat 参数中:

-Djava.library.path="C:\Program Files (x86)\IBM\WebSphere MQ\java\lib64"

If the installation directory is different than the above, use the appropriate location.

如果安装目录与上述不同,请使用适当的位置。