简体   繁体   English

IBM MQ MQCONN 从主机到 Docker 容器

[英]IBM MQ MQCONN from host to Docker container

Trying to connect from a C application running as an IBM MQ client on a host to an MQ server running as a docker container.尝试从在主机上作为 IBM MQ 客户端运行的 C 应用程序连接到作为 docker 容器运行的 MQ 服务器。

The client code taken from an IBM example is provided below.下面提供了从 IBM 示例中获取的客户端代码。 The questions is which protocol is used when MQCONN is called as no IP/port is provided?问题是在没有提供 IP/端口的情况下调用 MQCONN 时使用哪种协议? I can only guess it is some kind of an IPC.我只能猜测它是某种 IPC。 For this reason I'm running the docker container with --ipc="host" option, but it still fails with CompCode=2, Reason=2058出于这个原因,我正在运行带有 --ipc="host" 选项的 docker 容器,但它仍然失败,CompCode=2,Reason=2058

#include <cmqc.h>
⋮
static char Parm1[MQ_Q_MGR_NAME_LENGTH] ;
⋮
int  main(int argc, char *argv[] )
   {
   /*                                                    */
   /*     Variables for MQ calls                         */
   /*                                                    */
   MQHCONN Hconn;      /* Connection handle              */
   MQLONG  CompCode;   /* Completion code                */
   MQLONG  Reason;     /* Qualifying reason              */
⋮
   /* Copy the queue manager name, passed in the         */
   /* parm field, to Parm1                               */
   strncpy(Parm1,argv[1],MQ_Q_MGR_NAME_LENGTH);
⋮
   /*                                                    */
   /* Connect to the specified queue manager.            */
   /*   Test the output of the connect call.  If the     */
   /*   call fails, print an error message showing the   */
   /*   completion code and reason code, then leave the  */
   /*   program.                                         */
   /*                                                    */
   MQCONN(Parm1,
          &Hconn,
          &CompCode,
          &Reason);
   if ((CompCode != MQCC_OK) | (Reason != MQRC_NONE))
      {
      sprintf(pBuff, MESSAGE_4_E,
              ERROR_IN_MQCONN, CompCode, Reason);
      PrintLine(pBuff);
      RetCode = CSQ4_ERROR;
      goto AbnormalExit2;
      }
⋮
   }

If your program will be running on the same server as the queue manager then it is best to link it with 'mqm.lib' (bindings mode) rather than 'mqic.lib' (client mode).如果您的程序将与队列管理器在同一台服务器上运行,那么最好将其与“mqm.lib”(绑定模式)而不是“mqic.lib”(客户端模式)链接。

In the MQ KnowLedge Center , there are examples on how to compile and link your C program.MQ KnowLedge Center中,有关于如何编译和链接您的 C 程序的示例。 The examples are listed as: 'C client application' (client mode) and 'C server application' (bindings mode).示例列为:“C 客户端应用程序”(客户端模式)和“C 服务器应用程序”(绑定模式)。

If in the future, your C program needs to connect to a remote queue manager then you need to link it for 'client mode'.如果将来您的 C 程序需要连接到远程队列管理器,那么您需要将其链接为“客户端模式”。

To configure your C program to handle proper MQ security, change the MQCONN API call to MQCONNX API call.要配置您的 C 程序以处理适当的 MQ 安全性,请将 MQCONN API 调用更改为 MQCONNX API 调用。

ie IE

MQCNO   cno   = {MQCNO_DEFAULT};
MQCD    cd    = {MQCD_CLIENT_CONN_DEFAULT};
MQCSP   csp = {MQCSP_DEFAULT};

strncpy(cd.ConnectionName, hostname, MQ_CONN_NAME_LENGTH);
strncpy(cd.ChannelName, channelName, MQ_CHANNEL_NAME_LENGTH);

csp.AuthenticationType = MQCSP_AUTH_USER_ID_AND_PWD;

csp.CSPUserIdPtr = &myUserId;
csp.CSPUserIdOffset = 0;
csp.CSPUserIdLength = strlen(myUserId);

csp.CSPPasswordPtr = &myPassword;
csp.CSPPasswordOffset = 0;
csp.CSPPasswordLength = strlen(myPassword);

cno.cdPtr = &cd;
cno.Version = MQCNO_CURRENT_VERSION;
cno.SecurityParmsPtr = &csp;
cno.SecurityParmsOffset = 0;

MQCONNX(QMgrName, &cno, &Hcon, &CompCode, &Reason);

A few years ago, I wrote a blog posting called: MQ API Verbs that IBM Forgot!!几年前,我写了一篇名为: MQ API IBM 忘记的动词!! . . I created wraps for MQCONN and MQCONNX that will allow the program to pass UserId & Password for MQCONN and MQCONNX API calls.我为 MQCONN 和 MQCONNX 创建了包装,这将允许程序为 MQCONN 和 MQCONNX API 调用传递 UserId 和密码。 You may find it easier to simply use the wrappers.您可能会发现简单地使用包装器会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM