Java程序将WMQ与用户ID而不是通道连接
我有像使用用户ID(而不是通道)连接MQ的要求.
I have the requirement like connecting MQ with userid instead of channel.
我尝试在不使用Channel的情况下将用户ID和密码设置为MQEnvironment类,但是遇到了以下异常.
I have tried with setting user id and password without chanel to MQEnvironment class but got the below exception.
com.ibm.mq.jmqi.JmqiException: CC=2;RC=2540;AMQ9520: Channel not defined remotely. [3=].
请指导我,是否可以编写Java客户端来使用用户ID(而不是通道)连接MQ.
Please guide me, is it possible to write java client to connect MQ with user id instead of channel.
MQ应用程序有两种连接到队列管理器的方法:绑定和客户端模式.
There are 2 ways for an MQ application to connect to a queue manager: bindings and client mode.
-
绑定模式意味着您的MQ应用程序正在SAME上运行 服务器作为队列管理器.因此,MQI呼叫将不会使用 网络资源.
Bindings mode means that your MQ application is running on the SAME server as the queue manager. Hence, the MQI calls will not use network resources.
客户端模式意味着您的MQ应用程序可以在任何服务器上运行,并且 发出MQI呼叫时,它将使用网络资源.为了 MQCONN调用,除了队列管理器名称之外,您还需要 主机名/IP地址,端口号和通道名.
Client mode means that your MQ application can run on any server and it will use network resources when it issues MQI calls. For the MQCONN call, besides the queue manager name, you will also need the hostname/IP address, port # and channel name.
在任何一种情况下,您的MQ应用程序都应提供其用户凭据(用户ID和密码).
In either case, your MQ application should be supplying its user credentials (UserID & Password).
最后,不要使用MQEnvironment类.最好使用HashTable并将其传递给队列管理器构造函数类.即
Finally, do NOT use the MQEnvironment class. It is far, far better to use a HashTable and pass it to the queue manager constructor class. i.e.
Hashtable<String, Object> mqht = new Hashtable<String, Object>();
mqht.put(CMQC.CHANNEL_PROPERTY, channelName);
mqht.put(CMQC.HOST_NAME_PROPERTY, hostName);
mqht.put(CMQC.PORT_PROPERTY, new Integer(portNumber));
mqht.put(CMQC.USER_ID_PROPERTY, userID);
mqht.put(CMQC.PASSWORD_PROPERTY, password);
try
{
MQQueueManager qMgr = new MQQueueManager(qMgrName, mqht);
System.out.println("Successfully connected to "+ qMgrName);
}
catch (com.ibm.mq.MQException mqex)
{
System.out.println("MQException cc=" +mqex.completionCode + " : rc=" + mqex.reasonCode);
}