- 1、本文档共11页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
MQ开发C教程
?MQ发送消息和接收消息例子,/////////////?//MQ初始化??MQHOBJ?? hObj;?MQLONG? O_options, CompCode, Reason;?MQOD???? od? = {MQOD_DEFAULT};? // Object Descriptor?MQMD???? md? = {MQMD_DEFAULT};? // Message Descriptor?MQPMO??? pmo = {MQPMO_DEFAULT};? // put message options?MQGMO??? gmo = {MQGMO_DEFAULT};? // get message options ?memcpy(md.Format,MQFMT_STRING,??(size_t)MQ_FORMAT_LENGTH);??strncpy(od.ObjectName, QRECV_CL.TELECOM, (size_t)MQ_Q_NAME_LENGTH);?O_options = MQOO_INPUT_AS_Q_DEF??/* open queue for receive? */??+ MQOO_BROWSE ????+ MQOO_FAIL_IF_QUIESCING;??/* but not if MQM stopping */?MQOPEN(hConn, od, O_options, hObj, CompCode, Reason); ?if ( CompCode==MQCC_FAILED ) {??sprintf(sErrMsg, 打开队列: %s 失败, MQ_ERR_CODE: %d, sRecvQueue, Reason);???return -1;?}??//发送消息?md.Expiry = 60*10;?strncpy( od.ObjectName, QSEND_SR.ICBC, sizeof(od.ObjectName) );?//sMsgBuf 消息内容 piMsgLen 消息长度?MQPUT1(hConn, od, md, pmo, *piMsgLen, sMsgBuf, CompCode, Reason);?if(CompCode == MQCC_FAILED) {??sprintf(sErrMsg, 发送消息失败, MQ_ERR_CODE: %d, Reason);????if(hObj != MQHO_UNUSABLE_HOBJ)???MQCLOSE(hConn, hObj, MQCO_NONE, CompCode, Reason);??return -2;?}???dwStartTime = GetTickCount();??Sleep(1000);?bGetFistMsg = TRUE;???memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));?memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));??md.Version = MQMD_VERSION_2 ;?gmo.Version = MQGMO_VERSION_2;//?gmo.Options = MQGMO_BROWSE_NEXT;?//取回应消息?while(1)?{?????if(GetTickCount() - dwStartTime (unsigned)iGetResExpiry*1000) break;????if(bGetFistMsg == TRUE)??{???gmo.Options = MQGMO_BROWSE_FIRST;??}??else??{???gmo.Options = MQGMO_BROWSE_NEXT;??}???md.Encoding?????? = MQENC_NATIVE;??md.CodedCharSetId = MQCCSI_Q_MGR;??memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));??memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));???MQGET(hConn, hObj, md, gmo, MAX_THEEAD_BUF, sMsgBuf, (long *)piMsgLen, CompCode, Reason);??if(CompCode==MQCC_FAILED) {???if(Reason==MQRC_NO_MSG_AVAILABLE) {????????????????????Sleep(1000);????bGetFistMsg = TRUE;???//?DisplayMsg(无消息可取,T
文档评论(0)