简体   繁体   English

从 C# 连接到 MQ 多实例 (MQMI) 队列管理器

[英]Connecting to an MQ multi-instance (MQMI) queue manager from C#

Using IBM's sample code, I am able to connect to a single instance queue manager, and I am able to connect to a single instance of a multi-instance queue manager, but I cannot connect to the multi-instance queue manager.使用 IBM 的示例代码,我能够连接到单实例队列管理器,并且能够连接到多实例队列管理器的单个实例,但是我无法连接到多实例队列管理器。

I am using version 9.2 of ibm-mq-client.我正在使用 9.2 版的 ibm-mq-client。

When I use a single server as the host name everything works, but if I change it to a list ("iib-mq1.it.wd.com,iib-mq2.it.wd.com") it fails at the line:当我使用单个服务器作为主机名时,一切正常,但如果我将其更改为列表(“iib-mq1.it.wd.com,iib-mq2.it.wd.com”)它会失败:

MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

with the error:出现错误:

2298 MQRC_FUNCTION_NOT_SUPPORTED

My code:我的代码:

using IBM.WMQ;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace QueueInterface
{
class MQSample
{
    // The type of connection to use, this can be:-
    // MQC.TRANSPORT_MQSERIES_BINDINGS for a server connection.
    // MQC.TRANSPORT_MQSERIES_CLIENT for a non-XA client connection
    // MQC.TRANSPORT_MQSERIES_XACLIENT for an XA client connection
    // MQC.TRANSPORT_MQSERIES_MANAGED for a managed client connection

    const String connectionType = MQC.TRANSPORT_MQSERIES_MANAGED;

    // Define the name of the queue manager to use (applies to all connections)
    const String qManager = "TST_MQMI_QM";

    // Define the name of your host connection (applies to client connections only)
    //const String hostName = "iib-mq1.it.wd.com";
    const String hostName = "iib-mq1.it.wd.com,iib-mq2.it.wd.com";

    // Define the name of the channel to use (applies to client connections only)
    const String channel = "FHS.IIB.TS";

    const String userName = "iib-tst-usr";
    const String password = "randomPassword";
    const String port = "1212";
    const String queue = "TEST.ADD.FULL";


    /// <summary>
    /// Initialise the connection properties for the connection type requested
    /// </summary>
    /// <param name="connectionType">One of the MQC.TRANSPORT_MQSERIES_ values</param>
    static Hashtable init(String connectionType)
    {
        Hashtable connectionProperties = new Hashtable();

        // Add the connection type
        connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);

        // Set up the rest of the connection properties, based on the
        // connection type requested
        switch (connectionType)
        {
            case MQC.TRANSPORT_MQSERIES_BINDINGS:
                break;
            case MQC.TRANSPORT_MQSERIES_CLIENT:
            case MQC.TRANSPORT_MQSERIES_XACLIENT:
            case MQC.TRANSPORT_MQSERIES_MANAGED:
                connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
                connectionProperties.Add(MQC.PORT_PROPERTY, port);
                connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                connectionProperties.Add(MQC.USER_ID_PROPERTY, userName);
                connectionProperties.Add(MQC.PASSWORD_PROPERTY, password);
                connectionProperties.Add(MQC.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
                break;
        }

        return connectionProperties;
    }
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static int Main(string[] args)
    {
        try
        {
            Hashtable connectionProperties = init(connectionType);

            // Create a connection to the queue manager using the connection
            // properties just defined
            MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

            // Set up the options on the queue we want to open
            int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

            // Now specify the queue that we want to open,and the open options
            MQQueue system_default_local_queue = qMgr.AccessQueue(queue, openOptions);

            // Define an IBM MQ message, writing some text in UTF format
            MQMessage hello_world = new MQMessage();
            
            hello_world.WriteUTF("Sample Message");
            
            // Specify the message options
            MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
                                                                 // same as MQPMO_DEFAULT

            // Put the message on the queue
            system_default_local_queue.Put(hello_world, pmo);

            // Close the queue
            system_default_local_queue.Close();

            // Disconnect from the queue manager
            qMgr.Disconnect();
        }

        //If an error has occurred,try to identify what went wrong.

        //Was it an IBM MQ error?
        catch (MQException ex)
        {
            Console.WriteLine("An IBM MQ error occurred: {0}", ex.ToString());
        }

        catch (System.Exception ex)
        {
            Console.WriteLine("A System error occurred: {0}", ex.ToString());
        }

        return 0;
    }//end of start
}//end of sample
}

Instead of specifying a host and port you need to specify a connection name list.您需要指定连接名称列表,而不是指定主机和端口。 In below example I removed the variables to keep it simple.在下面的示例中,我删除了变量以使其简单。

Change:改变:

connectionProperties.Add(MQC.HOST_NAME_PROPERTY, "iib-mq1.it.wd.com,iib-mq2.it.wd.com");
connectionProperties.Add(MQC.PORT_PROPERTY, 1212);

To:至:

connectionProperties.Add(MQC.CONNECTION_NAME_PROPERTY,"iib-mq1.it.wd.com(1212),iib-mq2.it.wd.com(1212)")

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

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