用于创建.NET客户端

时间:2018-04-15 23:33:45

标签: c# ibm-mq

我需要使用CCDT文件将MQ.NET客户端连接到MQ服务器,两者都在本地运行,但是下面有错误。

IBM.WMQ.MQException: MQRC_Q_MGR_NAME_ERROR CompCode: 2, Reason: 2058

请在下面找到服务器设置和MQ.NET客户端。

服务器设置

我按照以下链接设置并创建了CCDT文件:

Setting up the server using IBM MQ Explorer

服务器连接频道:LOCAL.DEF.SVRCONN

MCA用户ID:我试图省略或提供它。无论是mqm的成员还是其中的任何成员。

Setting up the client using IBM MQ Explorer

Clinet channe:LOCAL.DEF.SVRCONN

队列管理器名称:LocalQM

连接名称:192.168.1.9(1415)

192.168.1.9是localhost address

1415是队列管理器,LocalQM,TCP端口。

IBM MQ.NET

代码位于here

之下
        MQQueueManager qm = null;
        System.Environment.SetEnvironmentVariable("MQCHLLIB", "C:\\ProgramData\\IBM\\MQ\\qmgrs\\LocalQM\\@ipcc");
        System.Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL.TAB");

        try
        {
            Hashtable props = new Hashtable();
            props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
            qm = new MQQueueManager("LocalQM",props);
            MQQueue queue1 = qm.AccessQueue("LocalQueue", MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage msg = new MQMessage();
            msg.WriteUTF("Hello this message is from .net client");
            queue1.Put(msg);
            queue1.Close();
            qm.Disconnect();
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }

Windows 10上的IBM MQ V8

Windows 10上的MQ.NET Client V8

Creating a client channel definition table

Using a client channel definition table with .NET

更新

如果我在不使用CCDT的情况下改为下面,那就可以了。

   var properties = new Hashtable
        {
            {MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED },         
             { MQC.HOST_NAME_PROPERTY, "192.168.1.9" }, //"localhost" },
        { MQC.PORT_PROPERTY, "1415"},
        { MQC.CHANNEL_PROPERTY, "LOCAL.DEF.SVRCONN" },
            {MQC.USER_ID_PROPERTY, "xxx" },  //usrename
            {MQC.PASSWORD_PROPERTY, "xxx" }  //password
        };
        _queueManager = new MQQueueManager(_queueManagerName, properties);

更新2 我将队列管理器更改为LocalQM

C:\Users\'#.lp\source>SET MQCHLLIB=C:\ProgramData\IBM\MQ\qmgrs\LocalQM\@ipcc

C:\Users\'#.lp\source>SET MQCHLTAB=AMQCLCHL.TAB

C:\Users\'#.lp\source>echo DIS CHL(LOCAL.DEF.SVRCONN) CHLTYPE(CLNTCONN) ALL | runmqsc -n
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting local MQSC for 'AMQCLCHL.TAB '.

     1 : DIS CHL(LOCAL.DEF.SVRCONN) CHLTYPE(CLNTCONN) ALL
AMQ8414: Display Channel details.
   CHANNEL(LOCAL.DEF.SVRCONN)              CHLTYPE(CLNTCONN)
   AFFINITY(PREFERRED)                     ALTDATE(2018-04-16)
   ALTTIME(22.16.03)                       CERTLABL( )
   CLNTWGHT(0)                             COMPHDR(NONE)
   COMPMSG(NONE)                           CONNAME(192.168.1.9 (1415))
   DEFRECON(NO)                            DESCR( )
   HBINT(300)                              KAINT(AUTO)
   LOCLADDR( )                             MAXMSGL(4194304)
   MODENAME( )                             PASSWORD( )
   QMNAME(LocalQM)                         RCVDATA( )
   RCVEXIT( )                              SCYDATA( )
   SCYEXIT( )                              SENDDATA( )
   SENDEXIT( )                             SHARECNV(10)
   SSLCIPH( )                              SSLPEER( )
   TPNAME( )                               TRPTYPE(TCP)
   USERID( )
No commands have a syntax error.

C:\Users\'#.lp\source>

更新3:MQRC_NOT_AUTHORIZED未解决

我改变了

  1. 192.168.1.9(1415) - > 192.168.1.9(1415)
  2. 将AMQCLCHL.TAB也放到C:\ ProgramData \ IBM \ MQ(我不知道为什么可能不正确,因为日志文件出错:

    AMQ9518:文件' C:\ ProgramData \ IBM \ MQ \ AMQCLCHL.TAB'没找到。

  3. 3我试过了 MCA用户ID - >

    1 mqclient是mqm的成员

    2 mqlclient谁不是mqm的成员

    3空

    但仍然有错误。以下是3.1

    的例外和错误
    IBM.WMQ.MQException: MQRC_NOT_AUTHORIZED
    
    ----- cmqxrsrv.c : 2356 -------------------------------------------------------
    17/04/2018 23:50:44 - Process(1848.16) User(SYSTEM) Program(amqzlaa0.exe)
                          Host(APPLE) Installation(Installation1)
                          VRMF(8.0.0.5) QMgr(LocalQM)
    
    AMQ5540: Application 'bin\Debug\Producer.exe' did not supply a user ID
    and password
    
    EXPLANATION:
    The queue manager is configured to require a user ID and password, but none was
    supplied.
    ACTION:
    Ensure that the application provides a valid user ID and password, or change
    the queue manager configuration to OPTIONAL to allow applications to connect
    which have not supplied a user ID and password. 
    ----- amqzfuca.c : 4311 -------------------------------------------------------
    17/04/2018 23:50:44 - Process(1848.16) User(SYSTEM) Program(amqzlaa0.exe)
                          Host(APPLE) Installation(Installation1)
                          VRMF(8.0.0.5) QMgr(LocalQM)
    
    AMQ5541: The failed authentication check was caused by the queue manager
    CONNAUTH CHCKCLNT(REQDADM) configuration.
    
    EXPLANATION:
    The user ID 'mqclient' and its password were checked because the user ID is
    privileged and the queue manager connection authority (CONNAUTH) configuration
    refers to an authentication information (AUTHINFO) object named
    'SYSTEM.DEFAULT.AUTHINFO.IDPWOS' with CHCKCLNT(REQDADM). 
    
    This message accompanies a previous error to clarify the reason for the user ID
    and password check.
    ACTION:
    Refer to the previous error for more information. 
    
    Ensure that a password is specified by the client application and that the
    password is correct for the user ID. The authentication configuration of the
    queue manager connection determines the user ID repository. For example, the
    local operating system user database or an LDAP server. 
    
    To avoid the authentication check, you can either use an unprivileged user ID
    or amend the authentication configuration of the queue manager. You can amend
    the CHCKCLNT attribute in the CHLAUTH record, but you should generally not
    allow unauthenticated remote access. 
    -------------------------------------------------------------------------------
    17/04/2018 23:50:45 - Process(14900.9) User(SYSTEM) Program(amqrmppa.exe)
                          Host(APPLE) Installation(Installation1)
                          VRMF(8.0.0.5) QMgr(LocalQM)
    
    AMQ9557: Queue Manager User ID initialization failed for 'mqclient'.
    
    EXPLANATION:
    The call to initialize the User ID 'mqclient' failed with CompCode 2 and Reason
    2035.
    ACTION:
    Correct the error and try again. 
    ----- cmqxrsrv.c : 2356 -------------------------------------------------------
    

2 个答案:

答案 0 :(得分:1)

OP在UPDATE 2中的问题中添加了以下信息:

  1. SET MQCHLLIB=C:\ProgramData\IBM\MQ\qmgrs\QM1\@ipcc
  2. SET MQCHLTAB=AMQCLCHL.TAB
  3. echo DIS CHL(LOCAL.DEF.SVRCONN) CHLTYPE(CLNTCONN) ALL | runmqsc -n
  4. 我看到CCDT有两个可能的问题:

    1. 您在IP和左括号之间的CONNAME中有一个空格。这可能导致MQ忽略端口1415并使用默认端口1414,它也可能忽略空间并且它可能不是问题,我从未测试过空间。

      COMPMSG(NONE)                           CONNAME(192.168.1.9 (1415))
      
    2. QMNAME频道的CLNTCONN应与您在调用new MQQueueManager时指定的内容相匹配,因此应该说QM1而不是LocalQM },这可能是导致2058错误的直接原因,但是一旦修复#2,#1可能会导致问题。

      QMNAME(LocalQM)                         RCVDATA( )
      
    3. QMNAME还有其他用途,您可以在其中指定组名称或空白。请参阅我对" Connecting to IBM MQ using CCDT file in JMS "的回答。有关这方面的更多细节。答案与JMS有关,但setQueueManager的信息与您调用new MQQueueManager的第一个参数相同。

答案 1 :(得分:0)

一般来说,原因代码2058(MQRC_Q_MGR_NAME_ERROR)表示您的队列管理器名称无效或服务器没有该特定队列管理器。检查您输入的队列管理器名称的拼写。此外,队列管理器名称区分大小写(例如,MQA1与mqa1不同)。

此外,每个队列管理器都有自己的端口#。即1414,1415,1416等。因此,如果该服务器上运行的队列管理器不止一个,那么请确保使用正确的端口。

System.Environment.SetEnvironmentVariable("MQCHLLIB", "C:\\ProgramData\\IBM\\MQ\\qmgrs\\QM1\\@ipcc");
System.Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL.TAB");

尝试在启动程序之前设置环境变量,而不是从程序内部设置。我在Windows和/或.NET中发现了一些奇怪的问题,在程序中设置了环境变量 - 有时它可以工作,有时它不会。

最后,您是否在运行队列管理器的同一服务器上运行应用程序?如果是,则连接到绑定模式'而不是客户端模式'。由于不涉及网络,绑定模式将更快。