【发布时间】:2021-06-04 01:48:31
【问题描述】:
使用 IBM 的示例代码,我能够连接到单实例队列管理器,并且能够连接到多实例队列管理器的单个实例,但我无法连接到多实例队列管理器。
我使用的是 ibm-mq-client 版本 9.2。
当我使用单个服务器作为主机名时,一切正常,但如果我将其更改为列表(“iib-mq1.it.wd.com,iib-mq2.it.wd.com”),它会失败行:
MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);
出现错误:
2298 MQRC_FUNCTION_NOT_SUPPORTED
我的代码:
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
}
【问题讨论】:
-
我的回答对你有用吗?
-
用 MQC.CONNECTION_NAME_PROPERTY 替换 MQC.HOST_NAME_PROPERTY 和 MQC.PORT_PROPERTY 解决了我遇到的问题。谢谢!