[求助] MQ分包发送的解决办法
请各位帮忙分析解决下MQ分包发送的问题。
个人感觉可能有些选项设置有问题,报文通过MQ发送过去,对方收不到。
具体函数如下:
- #define MQ_MAXSIZE 1024
- int mq_sendfile(MQH mqh, const char *filename,char * msg_id, char * cor_id)
- {
- /* Declare MQI structures needed */
- MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
- MQPMO pmo = {MQPMO_DEFAULT}; /* put message options */
- MQLONG RetCode; /* completion code */
- MQLONG Reason; /* reason code */
- MQLONG msglen;
- FILE *hFile;
- MQLONG lSendLeng,lDatalen;
- MQLONG iCount; /* File Segment count*/
- char msgbuf[MQ_MAXSIZE+1]; /* Temp Buffer*/
- if( mqh.obj_snd_flag == FALSE ) return(-1); /* object have not opend*/
- md.Encoding = MQENC_NATIVE;
- md.CodedCharSetId = 819;
- memcpy( md.MsgId, MQMI_NONE, sizeof(md.MsgId) );
- memcpy( md.CorrelId, MQCI_NONE, sizeof(md.CorrelId) );
- memcpy( md.Format, MQFMT_STRING, (size_t)MQ_FORMAT_LENGTH );
- /* put MsgId and CorrelId for match condition */
- if( msg_id[0] != 0x00 ) {
- memset( md.MsgId, 0x00, sizeof(md.MsgId) );
- strncpy( (char *)md.MsgId, msg_id, sizeof(md.MsgId) );
- }
- if( cor_id[0] != 0x00 ) {
- memset( md.CorrelId, 0x00, sizeof(md.CorrelId) );
- strncpy( (char *)md.CorrelId, cor_id, sizeof(md.CorrelId) );
- }
- iCount = 0;
- lSendLeng = 0;
- hFile = NULL;
- lDatalen = 0;
- if( filename == NULL) {
- swVdebug(0,"filename is null!");
- return (0);
- }
- if((hFile = fopen(filename,"rb"))==NULL){
- swVdebug(0,"open filename :%s error !",filename);
- return (-1);
- }
- /***
- md.Version = MQMD_VERSION_2;
- md.MsgFlags = MQMF_SEGMENT;
- pmo.Version = MQMD_VERSION_2;
- pmo.Options |= MQPMO_LOGICAL_ORDER;
- ***/
- int iTotal=0, iNum=0;
- while(1) {
- lSendLeng = fread(msgbuf,1,MQ_MAXSIZE,hFile);
- swVdebug(3,"read file :%s ,result:%ld !",filename, lSendLeng);
- md.Version = MQMD_VERSION_2;
- md.MsgFlags = MQMF_SEGMENT;
- pmo.Version = MQMD_VERSION_2;
- /*
- pmo.Options |= MQPMO_LOGICAL_ORDER|MQPMRF_GROUP_ID;
- pmo.Options = MQPMO_LOGICAL_ORDER ;
- pmo.PutMsgRecFields = MQPMRF_GROUP_ID;
- pmo.Options = MQPMO_LOGICAL_ORDER + MQPMO_SYNCPOINT ;
- pmo.Options = MQPMO_LOGICAL_ORDER|MQPMRF_GROUP_ID;
- pmo.Options = MQPMO_LOGICAL_ORDER ;
- pmo.PutMsgRecFields = MQPMRF_GROUP_ID;
- */
- pmo.Options = MQPMO_LOGICAL_ORDER ;
- pmo.PutMsgRecFields = MQPMRF_GROUP_ID;
- pmo.PutMsgRecOffset = iTotal;
- pmo.RecsPresent = iNum;
- if (lSendLeng < 0) {
- swVdebug(0,"read file error!");
- iCount = -1;
- break;
- }
- if ( lSendLeng == 0)
- break;
- if(lSendLeng < MQ_MAXSIZE)
- md.MsgFlags = MQMF_LAST_MSG_IN_GROUP;
- else
- md.MsgFlags = MQMF_MSG_IN_GROUP;
- msglen = lSendLeng;
- MQPUT( mqh.hcon, /* connection handle */
- mqh.hobj_snd, /* object handle */
- &md, /* message descriptor */
- &pmo, /* default options (datagram) */
- msglen, /* message length */
- msgbuf, /* message buffer */
- &RetCode, /* completion code */
- &Reason ); /* reason code */
- /* report reason, if any */
- swVdebug(3,"send mq count:%ld ,total:%ld,result:%d RetCode:%d !",iCount,lDatalen,Reason,RetCode);
- if(Reason != MQRC_NONE || RetCode == MQCC_FAILED || RetCode == MQCC_UNKNOWN) {
- mqh.reason = Reason;
- break;
- }
- iCount++;
- iNum ++;
- lDatalen += lSendLeng;
- iTotal += lSendLeng;
- swVdebug(3,"send mq OK ,count:%ld ,total:%ld,result:%d !",iCount,lDatalen,Reason);
- }
- fclose(hFile);
- return (lDatalen);
- }
复制代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论