Java program to connect WMQ with User Id instead of channel

可紊 提交于 2019-11-27 04:54:29

问题


I have the requirement like connecting MQ with userid instead of channel.

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=]."

Please guide me, is it possible to write java client to connect MQ with user id instead of channel.


回答1:


There are 2 ways for an MQ application to connect to a queue manager: bindings and client mode.

  • 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.

  • 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.

In either case, your MQ application should be supplying its user credentials (UserID & Password).

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);
}


来源:https://stackoverflow.com/questions/34628283/java-program-to-connect-wmq-with-user-id-instead-of-channel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!