请教关于连接MQ服务器的问题
本人按照网上找到的示例代码写了个程序发送消息到MQ服务器运行时报
Caused by: 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[Connection timed out: connect],3=168.8.5.20]],3=168.8.5.20(1418),5=RemoteTCPConnection.connnectUsingLocalAddress]
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1809)
at com.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:915)
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:224)
... 29 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2059;AMQ9213: 的通信出错。 [1=java.net.ConnectException[Connection timed out: connect],3=168.8.5.20]
at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:607)
at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.protocolConnect(RemoteTCPConnection.java:935)
at com.ibm.mq.jmqi.remote.internal.system.RemoteConnection.connect(RemoteConnection.java:1075)
at com.ibm.mq.jmqi.remote.internal.system.RemoteConnectionPool.getConnection(RemoteConnectionPool.java:338)
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiConnect(RemoteFAP.java:1488)
... 31 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection$2.run(RemoteTCPConnection.java:592)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.mq.jmqi.remote.internal.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:583)
... 35 more
请教各位大牛是什么原因呢?有人说是MQ版本问题,是不是项目引入的mq.jar包的版本啊
代码如下
private MQQueueManager getConnMQmanager() {
MQQueueManager qMgr=null;
MQEnvironment.hostname = "168.8.5.20";// MQ服务器IP
MQEnvironment.channel = "HTSC.OCRM.SMS.CHAN"; // 队列管理器对应的服务器连接通道
MQEnvironment.CCSID = 1381; // 字符编码
MQEnvironment.port = 1418; // 队列管理器的端口号
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_BINDINGS);
try {
qMgr = new MQQueueManager("HTSC.OCRM.SMS.QM");// 队列管理器名称
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return qMgr;
}
private void closeConnMQmanager(MQQueueManager qMgr) {
if (qMgr != null) {
try {
qMgr.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void sendMsg(String msgStr,MQQueueManager qMgr){
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF|MQC.MQOO_OUTPUT|MQC.MQOO_INQUIRE;
MQQueue queue = null;
try {
//建立Q1通道的连接
queue = qMgr.accessQueue("HTSC.SMS.SYNC.INFO_SMS.Q", openOptions, null, null,null);
MQMessage msg = new MQMessage();// 要写入队列的消息
msg.format = MQC.MQFMT_STRING;
msg.characterSet = 1381;
msg.writeObject(msgStr); //将消息写入消息对象中
MQPutMessageOptions pmo = new MQPutMessageOptions();
msg.expiry = -1; // 设置消息用不过期
queue.put(msg, pmo);// 将消息放入队列
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(queue!=null){
try {
queue.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
--------------------编程问答-------------------- 这个说得很清楚啊,你得先进行网络环境测试,比如:C:\> telnet 168.8.5.20 1418
Caused by: java.net.ConnectException: Connection timed out: connect --------------------编程问答-------------------- 可能是因为远程主机有防火墙阻挡。 --------------------编程问答-------------------- 看看防火墙。。。
补充:企业软件 , WebSphere