我对ibm mq很陌生,发现和mb相关的文档或书籍很少,我唯一找到的就是2004年写的《WebSphere MQ Using Java》。但是现实世界已经发生了很大的变化。我根据this在redhat linux 64位上成功安装并验证了mq server 7.5
我还创建了队列管理器myqm1
、队列LQ.TEST
、通道JAVA.CHANNEL
,并通过服务器上的命令行进行了一些测试,以确保它们运行良好。但是,当我在 windows xp 上安装 mq 客户端并在 java 代码下面编写时,它总是抛出一个exception:com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'
我的代码:
导入 com.ibm.mq.*;导入 com.ibm.mq.constants.MQConstants;
/** * 简单示例程序 */ public class MQSample {
// code identifier static final String sccsid = "@(#) MQMBID sn=p000-L120604 su=_H-IvIK4nEeGko6IWl3MDhA pn=MQJavaSamples/wmqjava/MQSample.java"; // define the name of the QueueManager private static final String qManager = "myqm1"; // and define the name of the Queue private static final String qName = "LQ.TEST"; /** * Main entry point * * @param args - command line arguments (ignored) */ public static void main(String args[]) { try { MQEnvironment.hostname = "58.2.221.196"; MQEnvironment.channel = "JAVA.CHANNEL"; MQEnvironment.port = 1414; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES); MQEnvironment.userID = "mqm"; MQEnvironment.password = "mqm"; MQEnvironment.CCSID = 1208; // Create a connection to the QueueManager System.out.println("Connecting to queue manager: " + qManager); MQQueueManager qMgr = new MQQueueManager(qManager); // Set up the options on the queue we wish to open int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT; // Now specify the queue that we wish to open and the open options System.out.println("Accessing queue: " + qName); MQQueue queue = qMgr.accessQueue(qName, openOptions); // Define a simple WebSphere MQ Message ... MQMessage msg = new MQMessage(); // ... and write some text in UTF8 format msg.writeUTF("Hello, World!"); // Specify the default put message options MQPutMessageOptions pmo = new MQPutMessageOptions(); // Put the message to the queue 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) { ex.printStackTrace(); System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode + " Reason Code " + ex.reasonCode); } catch (java.io.IOException ex) { System.out.println("An IOException occured whilst writing to the message buffer: " + ex); } return; } }
任何人都可以向我阐明这一点吗?我完全崩溃了。