public static void main(String args[]) { try { properties.put("hostname", "10.1.1.1"); properties.put("port", new Integer(1414)); properties.put("channel", "DC.SVRCONN"); properties.put("CCSID", new Integer(1381)); properties.put("transport","MQSeries");
// Create a connection to the queue manager qMgr = new MQQueueManager(qmName,properties); // Set up the options on the queue we wish to open... int openOptions = 16; // Now specify the queue that we wish to open, // and the open options... MQQueue remoteQ = qMgr.accessQueue(qName, openOptions);
// Define a simple WebSphere MQ message, and write some text in UTF format.. MQMessage putMessage = new MQMessage(); putMessage.writeUTF("Test"); // specify the message options... MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, same as MQPMO_DEFAULT // put the message on the queue remoteQ.put(putMessage,pmo); System.out.println("Message has been input into the Remote Queue");
// Close the queue... remoteQ.close(); // Disconnect from the queue manager qMgr.disconnect(); }catch (MQException ex) { // If an error has occurred in the above, try to identify what went wrong // Was it a WebSphere MQ error? System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode); }catch (IOException ex) { // Was it a Java buffer space error? System.out.println("An error occurred whilst writing to the message buffer: " + ex); }catch(Exception ex){ ex.printStackTrace(); } } } ------------------------------------------------------------------------------------------- 运行程序后,请在B机器的本地队列LQ_88888888中检查是否有消息存在,假如有说明测试成功。 读者可以自行编写把消息从对方的本地队列读取出来的程序。 假如读者对以上的内容有任何疑问,可以和我联系,qianh@cntmi.com 版权所有,严禁转载
参考资料: 1、《WebSphere MQ System Administration Guide》Third edition (May 2004),SC34-6068-02 2、《WebSphere MQ Using Java》Third edition (January 2004),SC34-6066-02 附件:MQTest.java(2K)