c - 我的C与MQ接收消息返回代码2037

标签 c ibm-mq

我运行 C 程序,它连接到 MQ 并尝试从中获取消息。我总是收到一条消息:
MQGET 结束,原因代码为 2037
表示MQ没有打​​开,但是MQOPEN CC=0 RC=0

MQ 错误日志为空。

这是程序

           #include <stdio.h>   
           #include <stdlib.h>      
           #include <string.h>      

           #include <cmqc.h>      /* includes for MQI*/              
           #include <cmqxc.h>   

           int main(int argc, char **argv)    
           {
           MQCNO   Connect_options = {MQCNO_DEFAULT};/MQNONNX opt*/   
           MQCD    ClientConn = {MQCD_CLIENT_CONN_DEFAULT};/*client channel*/  
           MQHCONN  Hcon;                   /* connection handle  */  
           MQHOBJ   Hobj;                   /* object handle */   
           MQLONG   CompCode;               /* completion code  */   
           MQLONG   OpenCode;               /* MQOPEN completion code*/  
           MQLONG   Reason;                 /* reason code    */   
           MQOD     od = {MQOD_DEFAULT};    /* Object Descriptor */   
           MQMD     md = {MQMD_DEFAULT};    /* Message Descriptor */   
           MQPMO    pmo = {MQPMO_DEFAULT};  /* put message options*/   
           MQLONG   O_options;              /* MQOPEN options  */   
           MQLONG   C_options;              /* MQCLOSE options */   
           MQGMO   gmo = {MQGMO_DEFAULT};   /* get message options */   

           char     QMgrName[MQ_Q_MGR_NAME_LENGTH+1];
           char     QName[MQ_Q_NAME_LENGTH+1];
           char     channelName[MQ_CHANNEL_NAME_LENGTH+1];
           char     hostname[1024];
           char     port[4];
           MQLONG   buflen;        /* buffer length*/
           char TempBuf[65536];
           int msgsToGet;
           int msgsGot;

           if (argc != 6)   
           {   
            printf("Usage: MQTest11 QMgrName ChlName hostname port  QName\n");   
            return(1);   
           }    

           **/* copy MQ manager name */**   
           strncpy(QMgrName, argv[1], MQ_Q_MGR_NAME_LENGTH);    
           QMgrName[MQ_Q_MGR_NAME_LENGTH] = '\0';    

           **/* copy channel name */**
           strncpy(channelName, argv[2], MQ_CHANNEL_NAME_LENGTH);    
           channelName[MQ_CHANNEL_NAME_LENGTH] = '\0';    

           **/* copy hostname */**
           strncpy(hostname, argv[3], 1023);    
           hostname[1023] = '\0'; 

           **/* copy port number */**   
           strncpy(port,argv[4],4);    
           strncpy(QName, argv[5], MQ_Q_NAME_LENGTH);    
           QName[MQ_Q_NAME_LENGTH] = '\0';    

           **/* copy hostname for connection */**
           strncpy(ClientConn.ConnectionName,hostname, MQ_CONN_NAME_LENGTH);    

           **/* copy channel name */**
           strncpy(ClientConn.ChannelName,channelName,MQ_CHANNEL_NAME_LENGTH);   

           **/* Point the MQCNO to the client connection definition */**   
           Connect_options.ClientConnPtr = &ClientConn;    
           Connect_options.Version = MQCNO_VERSION_2;    

           **/* use MQCONNX */**    

           if (CompCode == MQCC_FAILED)    
           {   
                /* exit with print the reason */    
           }    
           else    
           {    
            strncpy(od.ObjectName, QName, (size_t)MQ_Q_NAME_LENGTH);    
            O_options = MQOO_OUTPUT + MQOO_FAIL_IF_QUIESCING;    
            MQOPEN(Hcon,                      /* connection handle  */   
            &od,                       /* object descriptor for queue  */   
            O_options,                 /* open options                 */   
            &Hobj,                     /* object handle                */   
            &OpenCode,                 /* MQOPEN completion code       */   
            &Reason);                  /* reason code                  */   

            printf("MQTest11 MQOPEN CC=%ld RC=%ld\n", CompCode, Reason);

            if (OpenCode == MQCC_OK)    /* if MQOPEN , then continue in the while loop */      
            {    
            gmo.Options = MQGMO_WAIT + MQGMO_CONVERT;    
            gmo.WaitInterval = 15000;    
            msgsGot = 0;    
            msgsToGet = 0;    
            CompCode = OpenCode;    
            }    
             while (CompCode != MQCC_FAILED && ((msgsToGet == 0) || (msgsGot < msgsToGet)))    
            {   

           /* define length of the buffer -1 */   
           buflen = strlen(TempBuf) - 1;    */ buffer length */
           memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId)); /*copy msg ID*/     
           memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));/*copy corrlID*/      
           md.Encoding       = MQENC_NATIVE; /*encode*/   
           md.CodedCharSetId = MQCCSI_Q_MGR;   

           /* function to get message from MQ*/
           MQGET(Hcon,       /* get message from MQ */   
           Hobj,             /* object handle*/   
           &md,              /* message descriptor*/   
           &gmo,             /*get message options*/    
           buflen,           /*buffer length*/   
           TempBuf,          /* buffer */   
           &messlen,         /* message length*/   
           &CompCode,       /* completion code*/   
           &Reason);         /* reason code*/   

         **/* I put some statements to check if transaction failed or not*/**    
           if (Reason != MQRC_NONE)     
           {   
           if (Reason == MQRC_NO_MSG_AVAILABLE)   
           {   
           /* print statement no more messages */   
           else   
           {   
             printf("MQGET ended with reason code %d comcode %d\n",Reason,CompCode);       
            if (Reason == MQRC_TRUNCATED_MSG_FAILED)    
            {   
             /print statement that it is failed*/    
            }     
            }   
            }   

            **This is almost done, only statement if Compcode not failed, then print buffer**   

我已将 char TempBuf 声明更改为 MQBYTE,但没有帮助

最佳答案

MQRC 2037 是 MQRC_NOT_OPEN_FOR_INPUT,您可以通过运行 IBM MQ 客户端或服务器安装提供的 mqrc 命令来找到此信息,下面是 Linux 服务器上的示例输出:

$ mqrc 2037

      2037  0x000007f5  MQRC_NOT_OPEN_FOR_INPUT

您没有显示 MQOPEN 调用,但如果它使用 O_options,则会对此进行解释,您当前有以下内容:

O_options = MQOO_OUTPUT + MQOO_FAIL_IF_QUIESCING; 

这应该类似于以下内容:

O_options = MQOO_INPUT_AS_Q_DEF + MQOO_FAIL_IF_QUIESCING; 

我建议您查看随 IBM MQ 安装提供的示例应用程序。在 Linux 上,它们位于 /opt/mqm/samp 中。示例 amqsget0.c 与您的程序类似,只是它使用的是 MQCONN 而不是 MQCONNX。

关于c - 我的C与MQ接收消息返回代码2037,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44595396/

相关文章:

ibm-mq - 使用 Splunk 解析 IBM MQ v9.1 错误日志

java - 如何在java中设置IBM MQ GET预读MaximumSize

c - 如何读取整数值,直到在C中敲击字符 'o'?

c - 如何修复 C 中格式不一致或冗余的 char 'c'?

c - unsafePerformIO 和 FFI 库初始化

c# - MQ 在 C# 中与 SSL 连接

java - 使用 Java SSL 的 IBM MQ 错误代码 2397

c - 告诉 libavcodec/ffmpeg 丢帧

ios - 是否可以在不搜索 select/create 的情况下识别 sqlite3_step 执行的查询类型(select、create 等)?

java - 从 java 发送到 MQ 总是使用默认安装的 IBM MQ 版本 6.0 的 mqm 用户标识