/**//* * Created on 2005-1-18 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** *//** * @author Ralph * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ import com.ibm.mq.*; publicclass PtpSender ...{ publicstaticvoid main(String[] args) ...{ try...{ String hostName="neu"; String channel="ch_server"; String qManager="QM_guo"; String qName="Q_guo"; //set up the MQEnvironment properties for the client MQEnvironment.hostname=hostName; MQEnvironment.channel=channel; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES); MQEnvironment.CCSID=1381; //connetion to Q Manager MQQueueManager qMgr=new MQQueueManager(qManager); //set up the open options int openOptions=MQC.MQOO_OUTPUT|MQC.MQOO_FAIL_IF_QUIESCING; //open the Q MQQueue queue=qMgr.accessQueue(qName,openOptions,null,null,null); //set the put message options,will use the default settings MQPutMessageOptions pmo=new MQPutMessageOptions(); //build a message and write data MQMessage outMsg=new MQMessage(); //prepare message with the user data String msgString="Test Message from PtpSender program"; outMsg.writeUTF(msgString); //Now we put the message on the Q queue.put(outMsg,pmo); //commit the transaction qMgr.commit(); System.out.println("The message has been sussesfully put #####"); //close the Q and QManager objects queue.close(); qMgr.disconnect(); } catch(MQException ex)...{ System.out.println("completion code:"+ex.completionCode+" Reason code:"+ex.reasonCode); ex.printStackTrace(); } catch(Exception e)...{ e.printStackTrace(); } } } import com.ibm.mq.MQC; import com.ibm.mq.MQEnvironment; import com.ibm.mq.MQQueue; import com.ibm.mq.MQQueueManager; import com.ibm.*; import com.ibm.mq.*; /**//* * Created on 2005-1-18 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** *//** * @author Ralph * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ publicclass PtpReceiver ...{ publicstaticvoid main(String[] args) ...{ try...{ String hostName ="neu"; String channel ="ch_server"; String qManager ="QM_guo"; String qName ="Q_guo"; // set up the MQEnvironment properties for the client MQEnvironment.hostname = hostName; MQEnvironment.channel = channel; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES); MQEnvironment.CCSID =1381; // connetion to Q Manager MQQueueManager qMgr =new MQQueueManager(qManager); // set up the open options int openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING; // open the Q MQQueue queue = qMgr.accessQueue(qName, openOptions, null, null, null); // set get message options MQGetMessageOptions gmo =new MQGetMessageOptions(); gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT; gmo.options = gmo.options + MQC.MQGMO_WAIT; gmo.options = gmo.options + MQC.MQGMO_FAIL_IF_QUIESCING; gmo.waitInterval =3000; // build mssage MQMessage inMsg =new MQMessage(); // get the message from Q queue.get(inMsg, gmo); // read the data from the message String msgString = inMsg.readUTF(); System.out.println("The Message from Q is :"+ msgString); // commit the trasaction qMgr.commit(); // close the Q and connection queue.close(); qMgr.disconnect(); }catch (MQException ex) ...{ System.out.println("Completion code is:"+ ex.completionCode +" reason code is:"+ ex.reasonCode); ex.printStackTrace(); }catch (Exception e) ...{ e.printStackTrace(); } } }
文档中的源程序没有红色部分的代码,这是我在调试的过程中出现提示:队列管理器没有打开CCSID功能的提示。经过在网上找资料和查看文档,最后知道是由于Windows 2000与Windows XP CCSID不同导致的,所以在代码中对CCSID的值进行显示的负值后问题解决了。