【问题标题】:Get Active QM Instance from Multi Instance Queue Manager and connect从多实例队列管理器获取活动 QM 实例并连接
【发布时间】:2017-12-11 08:42:01
【问题描述】:

在将队列管理器的单个实例更改为多实例队列管理器时,我无法为多实例队列管理器定义多个主机名。 现有主机在 web.config 中定义

<QueueConfigurationSection>
    <QueueConfiguration>
        <add name="SomeQueueHandler" queueManager="QM1" host="99.99.99.01" port="12345" requestQueue="A.B.REQUEST" service="FLATFILE" responseQueue="B.A.RESPONSE" internalResponseQueue="B.A.INTERNAL" channel="A.SVC.SVRCONN" binding="SOAP11TcpBinding" endPoint="net.tcp://localhost:808/Bus/SomeServiceBus.svc/SOAP11" />
    </QueueConfiguration>
  </QueueConfigurationSection>

这里定义了连接

public List<QueueHandler> Queues
{
    get
    {
        if (_queues == null)
            _queues = new List<QueueHandler>();
        if (_queues.Count == 0 && _queueConfiguration != null)
        {
            //create queue handlers from configuration provided
            foreach (QueueConfigurationElement element in _queueConfiguration)
            {
                // Using a different connection factory for each queue
                XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
                IConnectionFactory connectionProperties = factory.CreateConnectionFactory();
                connectionProperties.SetStringProperty(XMSC.WMQ_HOST_NAME, element.Host);
                connectionProperties.SetIntProperty(XMSC.WMQ_PORT, element.Port);
                connectionProperties.SetStringProperty(XMSC.WMQ_CHANNEL, element.Channel); 
                connectionProperties.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
                connectionProperties.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
                connectionProperties.SetBooleanProperty(XMSC.WMQ_USE_CONNECTION_POOLING, true);

                var queue = new QueueHandler(element.Name, connectionProperties);
                _queues.Add(queue);
            }
        }
        return new List<QueueHandler>(_queues);
    }
}

队列处理程序:

public QueueHandler(string handlerName, IConnectionFactory mqConnectionFactory)
{
    _connectionProperties = mqConnectionFactory;
    var queueConfigurationSection = ConfigurationManager.GetSection(QueueConfigurationSection.SectionName) as QueueConfigurationSection;
    if (queueConfigurationSection != null)
    {
        if (queueConfigurationSection.QueueConfigurationCollection.Cast<QueueConfigurationElement>().Any(qc => qc.Name == handlerName))
        {
            var element = queueConfigurationSection.QueueConfigurationCollection.Cast<QueueConfigurationElement>().First(qc => qc.Name == handlerName);

            _name = element.Name;
            _serviceType = element.DestinationService;
            _queueManagerName = element.QueueManager;
            _channel = element.Channel;
            _requestQueueName = element.RequestQueue;
            _responseQueueName = element.ResponseQueue;
            _internalResponseQueueName = element.InternalResponseQueue;
            _port = element.Port;
            _host = element.Host;

            //set up binding configuraion
            EndpointType bindingEnum;
            if (System.Enum.TryParse(element.Binding, out bindingEnum))
            {
                _messageType = bindingEnum;

                switch (bindingEnum)
                {
                    case EndpointType.FlatFileTcpBinding:
                        //message received from the request queue is plain text - by configuration
                        _dvsBinding = EndpointHelper.CreateFlatFileTCPBinding();
                        break;
                    // ...
                    default:
                        //unsupported endpoint configuration
                        throw new Exception("Unsupported binding configuration");
                }
            }

            //create endpoint address
            _endPointAddress = new EndpointAddress(element.EndPoint);
        }
    }
}

并且主机名和端口也在同一个类中的 SendNewMessage 方法中定义...

try
        {
            if (port != 0)
                MQEnvironment.Port = port;
            if (host != ".")
                MQEnvironment.Hostname = host;
            if (channel != ".")
                MQEnvironment.Channel = channel;
            hMgr = new MQQueueManager(manager);
        }

那么如何在 MQEnvironment.Hostname 中设置备用主机呢?

【问题讨论】:

    标签: ibm-mq xms


    【解决方案1】:

    有多种方法可以为 MQ 提供多个要连接的主机名和端口号。我在下面的建议指定的设置类似于您已经指定主机和端口的方式。


    对于使用 XMS 的 QueueHandler,您可以将属性 XMSC.WMQ_HOST_NAME 和 XMSC.WMQ_PORT 替换为以下三个属性。下面的示例假设您在 web.config 中定义了 host1、port1、host2、port2:

    connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_OPTIONS, XMSC.WMQ_CLIENT_RECONNECT_Q_MGR);
    connectionProperties.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, String.Format("{0}({1}),{2}({3})", element.Host1, element.Port1, element.Host2, element.Port2));
    connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT, XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT_DEFAULT);
    

    这些属性的 IBM MQ 知识中心页面的链接:

    在 IBM 安装目录下,您可以查看以下 XMS 示例程序:

    tools\dotnet\samples\cs\xms\simple\wmq\SimpleClientAutoReconnect\SimpleClientAutoReconnect.cs
    

    对于使用 IBM MQ C# 库编写的 SendNewMessage 方法,您可以将 MQEnvironment 设置替换为属性的 Hashtable,并更改调用 MQQueueManager 的方式以传递 Hashtable。这具有额外的好处,即在 MQEnvironment 不是线程安全的情况下是线程安全的。下面的示例假设您在 web.config 中定义了 host1、port1、host2、port2:

    properties = new Hashtable();
    properties.Add(MQC.CONNECTION_NAME_PROPERTY, String.Format("{0}({1}),{2}({3})", host1, port1, host2, port2));
    properties.Add(MQC.CHANNEL_PROPERTY, channel);
    properties.Add(MQC.CONNECT_OPTIONS_PROPERTY, MQC.MQCNO_RECONNECT_Q_MGR);
    hMgr = new MQQueueManager(manager, properties);
    

    IBM MQ 知识中心页面“MQQueueManager .NET class”包含有关属性的更多信息。

    在 IBM 安装目录下,您可以查看以下 C# 示例程序:

    tools\dotnet\samples\cs\base\SimpleClientAutoReconnectPut\SimpleClientAutoReconnectPut.cs
    

    【讨论】:

    • 请参阅What should I do when someone answers my question?。如果你喜欢它,请接受它和/或投票。很高兴能帮上忙。
    • 仍然不起作用...当我使用连接属性创建这样的连接时:connectionWMQ = cf.CreateConnection(); sessionWMQ = connectionWMQ.CreateSession(false,AcknowledgeMode.AutoAcknowledge);目的地 = sessionWMQ.CreateQueue(destinationName);生产者 = sessionWMQ.CreateProducer(destination);它抛出异常:...下一条评论
    • XMS 尝试执行 MQPUT 或 MQPUT1;但是 WebSphere MQ 报告了一个错误。使用链接异常来确定此错误的原因。堆栈跟踪:在 IBM.XMS.Client.WMQ.ProducerShadow.CheckNmqiCallSuccess(String messageid, WmqDestination destination, String probeid, Int32 cc, Int32 rc)
    • 来自“sessionWMQ.CreateProducer(destination)”的生产者我可以看到 XMSC_WMQ_CONNECTION_NAME_LIST : hostname1(11111),hostname2(11111)。但是它也显示“XMSC_WMQ_HOST_NAME:localhost”和“XMSC_WMQ_PORT:1414”。这就是它试图连接并抛出异常的原因吗?
    • @Leo 请点击您问题下方的编辑并添加详细信息。 cmets 格式不正确,因此难以阅读。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多