问题描述
本人按照网上找到的示例代码写了个程序发送消息到MQ服务器运行时报Causedby:com.ibm.mq.jmqi.JmqiException:CC=2;RC=2059;AMQ9204:与主机'168.8.5.20(1418)'的连接被拒绝。[1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2059;AMQ9213:的通信出错。[1=java.net.ConnectException[Connectiontimedout:connect],3=168.8.5.20]],3=168.8.5.20(1418),5=RemoteTCPConnection.connnectUsingLocalAddress]atcom.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1809)atcom.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:915)atcom.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:224)...29moreCausedby:com.ibm.mq.jmqi.JmqiException:CC=2;RC=2059;AMQ9213:的通信出错。[1=java.net.ConnectException[Connectiontimedout:connect],3=168.8.5.20]atcom.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:607)atcom.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.protocolConnect(RemoteTCPConnection.java:935)atcom.ibm.mq.jmqi.remote.internal.system.RemoteConnection.connect(RemoteConnection.java:1075)atcom.ibm.mq.jmqi.remote.internal.system.RemoteConnectionPool.getConnection(RemoteConnectionPool.java:338)atcom.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1488)...31moreCausedby:java.net.ConnectException:Connectiontimedout:connectatjava.net.PlainSocketImpl.socketConnect(NativeMethod)atjava.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)atjava.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)atjava.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)atjava.net.Socket.connect(Socket.java:452)atjava.net.Socket.connect(Socket.java:402)atcom.ibm.mq.jmqi.remote.internal.RemoteTCPConnection$2.run(RemoteTCPConnection.java:592)atjava.security.AccessController.doPrivileged(NativeMethod)atcom.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:583)...35more请教各位大牛是什么原因呢?有人说是MQ版本问题,是不是项目引入的mq.jar包的版本啊代码如下privateMQQueueManagergetConnMQmanager(){MQQueueManagerqMgr=null;MQEnvironment.hostname="168.8.5.20";//MQ服务器IPMQEnvironment.channel="HTSC.OCRM.SMS.CHAN";//队列管理器对应的服务器连接通道MQEnvironment.CCSID=1381;//字符编码MQEnvironment.port=1418;//队列管理器的端口号MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_BINDINGS);try{qMgr=newMQQueueManager("HTSC.OCRM.SMS.QM");//队列管理器名称}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnqMgr;}privatevoidcloseConnMQmanager(MQQueueManagerqMgr){if(qMgr!=null){try{qMgr.close();}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}privatevoidsendMsg(StringmsgStr,MQQueueManagerqMgr){intopenOptions=MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT|MQC.MQOO_INQUIRE;MQQueuequeue=null;try{//建立Q1通道的连接queue=qMgr.accessQueue("HTSC.SMS.SYNC.INFO_SMS.Q",openOptions,null,null,null);MQMessagemsg=newMQMessage();//要写入队列的消息msg.format=MQC.MQFMT_STRING;msg.characterSet=1381;msg.writeObject(msgStr);//将消息写入消息对象中MQPutMessageOptionspmo=newMQPutMessageOptions();msg.expiry=-1;//设置消息用不过期queue.put(msg,pmo);//将消息放入队列}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{if(queue!=null){try{queue.close();}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}}
解决方案
解决方案二:
这个说得很清楚啊,你得先进行网络环境测试,比如:C:>telnet168.8.5.201418Causedby:java.net.ConnectException:Connectiontimedout:connect
解决方案三:
可能是因为远程主机有防火墙阻挡。
解决方案四:
看看防火墙。。。