【发布时间】:2017-02-12 11:25:35
【问题描述】:
我正在尝试使用 Java 程序连接到 IBM websphere Client 以下是代码:=
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
/**
* Simple example program
*/
public class MQSample {
// code identifier
static final String sccsid = "@(#) MQMBID sn=p750-002-131001_DE su=_FswqMCqGEeOZ3ui-rZDONA pn=MQJavaSamples/wmqjava/MQSample.java";
// define the name of the QueueManager
private static final String qManager = "QM_ORANGE";
// and define the name of the Queue
private static final String qName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
// private static final String qName = "QM_APPLE";
public static void main(String args[]) {
try {
System.out.println("Connecting to queue manager: " + qManager);
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions =1| 16;
System.out.println("Accessing queue: " + qName);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
MQMessage msg = new MQMessage();
msg.writeUTF("Hello, World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
System.out.println("Sending a message...");
queue.put(msg, pmo);
// Now get the message back again. First define a WebSphere MQ
// message
// to receive the data
// MQMessage rcvMessage = new MQMessage();
// Specify default get message options
// MQGetMessageOptions gmo = new MQGetMessageOptions();
// Get the message off the queue.
// System.out.println("...and getting the message back again");
// queue.get(rcvMessage, gmo);
// And display the message text...
//String msgText = rcvMessage.readUTF();
// System.out.println("The message is: " + msgText);
// Close the queue
System.out.println("Closing the queue");
queue.close();
// Disconnect from the QueueManager
System.out.println("Disconnecting from the Queue Manager");
qMgr.disconnect();
System.out.println("Done!");
}
catch (MQException ex) {
System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode
+ " Reason Code " + ex.reasonCode);
ex.printStackTrace();
for (Throwable t = ex.getCause(); t != null; t = t.getCause()) {
System.out.println("... Caused by ");
t.printStackTrace();
}
}
catch (java.io.IOException ex) {
System.out.println("An IOException occured whilst writing to the message buffer: " + ex);
}
return;
}
}
但现在我收到以下错误
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.ibm.mq.MQSESSION.loadLib(MQSESSION.java:872)
at com.ibm.mq.server.MQSESSION$1.run(MQSESSION.java:228)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.mq.server.MQSESSION.<clinit>(MQSESSION.java:222)
at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:70)
at com.ibm.mq.MQSESSION.getSession(MQSESSION.java:492)
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:168)
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:179)
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:215)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:84)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:168)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:772)
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:697)
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:657)
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:153)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:451)
at MQSample.main(MQSample.java:30)
当我提到这个每个人都说把 mqjbnd.dll 放在 java.library 中时,我把那个文件放在那个路径中也仍然无法工作
【问题讨论】:
-
如果可能,建议使用使用 JMS 的 100% Java 客户端。 b/c 更容易编码和部署,不需要本地库。
-
@马特。不好的答案。 (1) 也许他们不想使用 JMS & (2) 即使他们使用 JMS,他们仍然需要供应商特定的 JMS JAR 文件。
-
@Roger7 1) 这不是答案,而是评论。 2) 他们对使用非 JMS IBM java 客户端库的本机 c 库有问题。使用 JMS+IBMMQ-jar 是 100% java 并且更易于编码和部署。看过 100 次... 99 次用户移动到 JMS 库。 JMS 库还使用 targetClient=0 为另一端的非 JMS WMQ 客户端提供向后兼容。
-
@Matt,他/她的问题不是本机文件与纯 JAR 文件。 99% 的人确定他们有错误的代码并在他们应该以“客户端模式”连接时以“绑定模式”连接。让您大吃一惊:如果您使用“JMS+IBMMQ-jar 是 100% java”并以“绑定模式”连接,那么它将始终使用 mqjbnd05 DLL/共享库!!!!!!
-
@Roger。是的,我知道。除非有极端性能用例(很少出现这种情况),否则出于代码重用和标准一致性的原因,应尽可能避免使用 WMQ 原生 API 和绑定模式方法。