怎么样解决使用MQ时遇到的CCSID问题?
今天在做MQ的一个例子程序的时候,遇到了CCSID问题,还好弄了半天终于搞定了 :)
今天把MQ文档中的例子拿来做了一下,在调试的过程中遇到了CCSID问题。
下面先把程序总体思路说一下,软硬件的环境是:我使用一台PC机做服务器,并在这台机器上安装WebSphere MQ的服务器。然后把另外一台PC机作为客户端,并且在这台机器上安装WebSphere MQ的Windows 版客户端。服务器端的操作系统是Windows 2000 Professional,客户端是Windows XP。
我做的这个例子是通过客户端的方式来向服务器传递消息。服务器上的MQ中的参数为:
hostname:neu
MQM name: QM_guo
Channel name:ch_server
Q name:Q_guo
PtpSender.java(用于向服务器端传递消息) PtpReceiver.java(用于从服务器端得到消息)
程序代码如下:

/**//*
*Createdon2005-1-18
*
*TODOTochangethetemplateforthisgeneratedfilegoto
*Window-Preferences-Java-CodeStyle-CodeTemplates
*/


/***//**
*@authorRalph
*
*TODOTochangethetemplateforthisgeneratedtypecommentgoto
*Window-Preferences-Java-CodeStyle-CodeTemplates
*/
importcom.ibm.mq.*;

publicclassPtpSender...{


publicstaticvoidmain(String[]args)...{

try...{
StringhostName="neu";
Stringchannel="ch_server";
StringqManager="QM_guo";
StringqName="Q_guo";


//setuptheMQEnvironmentpropertiesfortheclient
MQEnvironment.hostname=hostName;
MQEnvironment.channel=channel;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
MQEnvironment.CCSID=1381;
//connetiontoQManager
MQQueueManagerqMgr=newMQQueueManager(qManager);

//setuptheopenoptions
intopenOptions=MQC.MQOO_OUTPUT|MQC.MQOO_FAIL_IF_QUIESCING;

//opentheQ
MQQueuequeue=qMgr.accessQueue(qName,openOptions,null,null,null);

//settheputmessageoptions,willusethedefaultsettings
MQPutMessageOptionspmo=newMQPutMessageOptions();

//buildamessageandwritedata
MQMessageoutMsg=newMQMessage();


//preparemessagewiththeuserdata
StringmsgString="TestMessagefromPtpSenderprogram";
outMsg.writeUTF(msgString);

//NowweputthemessageontheQ
queue.put(outMsg,pmo);

//committhetransaction
qMgr.commit();

System.out.println("Themessagehasbeensussesfullyput #####");

//closetheQandQManagerobjects
queue.close();
qMgr.disconnect();

}

catch(MQExceptionex)...{
System.out.println("completioncode:"+ex.completionCode+" Reasoncode:"+ex.reasonCode);
ex.printStackTrace();
}

catch(Exceptione)...{
e.printStackTrace();
}
}
}



importcom.ibm.mq.MQC;
importcom.ibm.mq.MQEnvironment;
importcom.ibm.mq.MQQueue;
importcom.ibm.mq.MQQueueManager;
importcom.ibm.*;
importcom.ibm.mq.*;


/**//*
*Createdon2005-1-18
*
*TODOTochangethetemplateforthisgeneratedfilegoto
*Window-Preferences-Java-CodeStyle-CodeTemplates
*/


/***//**
*@authorRalph
*
*TODOTochangethetemplateforthisgeneratedtypecommentgotoWindow-
*Preferences-Java-CodeStyle-CodeTemplates
*/

publicclassPtpReceiver...{


publicstaticvoidmain(String[]args)...{

try...{
StringhostName="neu";
Stringchannel="ch_server";
StringqManager="QM_guo";
StringqName="Q_guo";

//setuptheMQEnvironmentpropertiesfortheclient
MQEnvironment.hostname=hostName;
MQEnvironment.channel=channel;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);
MQEnvironment.CCSID=1381;
//connetiontoQManager
MQQueueManagerqMgr=newMQQueueManager(qManager);

//setuptheopenoptions
intopenOptions=MQC.MQOO_INPUT_SHARED
|MQC.MQOO_FAIL_IF_QUIESCING;

//opentheQ
MQQueuequeue=qMgr.accessQueue(qName,openOptions,null,null,
null);

//setgetmessageoptions
MQGetMessageOptionsgmo=newMQGetMessageOptions();
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;

//buildmssage
MQMessageinMsg=newMQMessage();

//getthemessagefromQ
queue.get(inMsg,gmo);

//readthedatafromthemessage
StringmsgString=inMsg.readUTF();
System.out.println("TheMessagefromQis:"+msgString);

//committhetrasaction
qMgr.commit();

//closetheQandconnection
queue.close();
qMgr.disconnect();

}catch(MQExceptionex)...{
System.out.println("Completioncodeis:"+ex.completionCode
+" reasoncodeis:"+ex.reasonCode);
ex.printStackTrace();

}catch(Exceptione)...{
e.printStackTrace();
}
}
}

