您好,我在使用JMS连接到IBM WebSphere MQ时遇到一个大问题
我用:
赢7
JDK 1.7
IBM WebSphere MQ服务器7.5.0.2
GlassFish 4.0
我制作了一个名为test1
的QueueManager和一个名为test1q
的队列,以及一个名为test1channel
的协商通道
我的代码在这里:
StandaloneSender s = new StandaloneSender();
try{
s.send(“hello word”);
}catch (Exception e){
e.printStackTrace();
}
StandaloneSender.java
import javax.jms.Message;
import javax.jms.QueueConnection;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.NamingException;
public class StandaloneSender {
private P2PUtils utils;
private QueueConnection connection;
private QueueSession session;
private QueueSender sender;
public void send(String message) throws NamingException, JMSException, IOException {
StandaloneSender sender = new StandaloneSender();
sender.connect();
sender.sendMessage(message);
sender.disconnect();
}
public StandaloneSender() {
utils = new P2PUtils();
}
private void connect() throws NamingException, JMSException {
connection = utils.getConnection();
session =
connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createSender(utils.getQueue());
System.out.println("Sender started.");
}
private void sendMessage(String text) throws JMSException {
Message message = session.createTextMessage(text);
sender.send(message);
System.out.println(
"Sent message <"
+ text
+ "> with ID <"
+ message.getJMSMessageID()
+ ">");
}
private void disconnect() throws JMSException {
sender.close();
session.close();
connection.close();
System.out.println("Sender stopped.");
}
}
P2PUtils.java
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.naming.Context;
import javax.naming.NamingException;
public class P2PUtils extends JmsUtils {
private static final String QCF_NAME = "test1";
private static final String QUEUE_NAME = "test1q";
public QueueConnection getConnection() throws NamingException, JMSException {
Context context = getInitialContext();
QueueConnectionFactory qcf =
(QueueConnectionFactory) context.lookup(QCF_NAME);
return qcf.createQueueConnection();
}
public Queue getQueue() throws NamingException {
Context context = getInitialContext();
return (Queue) context.lookup(QUEUE_NAME);
}
}
JmsUtils.java
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class JmsUtils {
private static final String CF_CLASS_NAME = "com.ibm.mq.jms.context.WMQInitialContextFactory";
private static final String WMQ_URL = "localhost:1414/SYSTEM.DEF.SVRCONN";
protected Context getInitialContext() throws NamingException {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, CF_CLASS_NAME);
props.put(Context.PROVIDER_URL, WMQ_URL);
return new InitialContext(props);
}
}
但是我从玻璃鱼那里得到了一个例外:
[2014-02-17T16:35:25.286+0330] [glassfish 4.0] [SEVERE] [] [] [tid: _ThreadID=25 _ThreadName=Thread-4] [timeMillis: 1392642325286] [levelValue: 1000] [[
javax.naming.ServiceUnavailableException: Unable to connect to the target queue manager localhost:1414/SYSTEM.DEF.SVRCONN [Root exception is com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2539'.]
at com.ibm.mq.jms.context.MQContext.<init>(MQContext.java:196)
at com.ibm.mq.jms.context.WMQInitialContextFactory.getInitialContext(WMQInitialContextFactory.java:29)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at com.surena.MQ.JmsUtils.getInitialContext(JmsUtils.java:17)
at com.surena.MQ.P2PUtils.getConnection(P2PUtils.java:16)
at com.surena.MQ.StandaloneSender.connect(StandaloneSender.java:32)
at com.surena.MQ.StandaloneSender.send(StandaloneSender.java:22)
at com.surena.servlet.MainServlet.doGet(MainServlet.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2539'.
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:247)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:588)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:630)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:107)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:205)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:911)
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:799)
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:750)
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:157)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:757)
at com.ibm.mq.pcf.PCFAgent.connect(PCFAgent.java:230)
at com.ibm.mq.pcf.PCFAgent.<init>(PCFAgent.java:163)
at com.ibm.mq.pcf.PCFMessageAgent.<init>(PCFMessageAgent.java:140)
at com.ibm.mq.jms.context.MQContext.<init>(MQContext.java:183)
... 39 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2539;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2539;AMQ9503: Channel negotiation failed. [3=SYSTEM.DEF.SVRCONN]],3=localhost(1414),5=RemoteConnection.initSess]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2053)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1226)
at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:311)
at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:337)
at com.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:924)
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:236)
... 52 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2539;AMQ9503: Channel negotiation failed. [3=SYSTEM.DEF.SVRCONN]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1111)
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:727)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:400)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:299)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:164)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1598)
... 57 more]]
这是来自IBM MQ
2/17/2014 14:41:51 - Process(3924.1) User(MUSR_MQADMIN) Program(runmqlsr.exe)
Host(PROGRAMMER1) Installation(Installation1)
VRMF(7.5.0.2)
AMQ6118: An internal WebSphere MQ error has occurred (20006047)
EXPLANATION:
An error has been detected, and the MQ error recording routine has been called.
ACTION:
Use the standard facilities supplied with your system to record the problem
identifier and to save any generated output files. Use either the MQ Support
site: http://www.ibm.com/software/integration/wmq/support/, or IBM Support
Assistant (ISA): http://www.ibm.com/software/support/isa/, to see whether a
solution is already available. If you are unable to find a match, contact your
IBM support center. Do not discard these files until the problem has been
resolved.
----- amqxfdcp.c : 867 --------------------------------------------------------
2/17/2014 14:41:51 - Process(3924.1) User(MUSR_MQADMIN) Program(runmqlsr.exe)
Host(PROGRAMMER1) Installation(Installation1)
VRMF(7.5.0.2)
AMQ6184: An internal WebSphere MQ error has occurred on queue manager test1
.
EXPLANATION:
An error has been detected, and the WebSphere MQ error recording routine has
been called. The failing process is process 3924.
ACTION:
Use the standard facilities supplied with your system to record the problem
identifier and to save any generated output files. Use either the MQ Support
site: http://www.ibm.com/software/integration/wmq/support/, or IBM Support
Assistant (ISA): http://www.ibm.com/software/support/isa/, to see whether a
solution is already available. If you are unable to find a match, contact your
IBM support center. Do not discard these files until the problem has been
resolved.
我使用了MQ安装目录中包含的所有jar文件
请帮我。
最佳答案
从玻璃鱼的例外中,我挑出了一些有趣的地方:
javax.naming.ServiceUnavailableException: Unable to connect to the target
queue manager localhost:1414/SYSTEM.DEF.SVRCONN [Root exception is
com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2539'.
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2539;
AMQ9204: Connection to host 'localhost(1414)' rejected.
[1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2539;
AMQ9503: Channel negotiation failed. [3=SYSTEM.DEF.SVRCONN]],
3=localhost(1414),5=RemoteConnection.initSess]
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2539;
AMQ9503: Channel negotiation failed. [3=SYSTEM.DEF.SVRCONN]
这里有各种提示给您。第一个是MQRC返回代码2539。您可以使用IBM MQ随附的mqrc命令行工具进行查找。只要输入
mqrc 2539
,它就会报告:-2539 0x000009eb MQRC_CHANNEL_CONFIG_ERROR.
另外,我们还有一些错误消息:
AMQ9204: Connection to host 'localhost(1414)' rejected.
AMQ9503: Channel negotiation failed. [3=SYSTEM.DEF.SVRCONN]
您也可以使用mqrc工具查看完整的错误消息说明,只需键入
mqrc AMQ9204
。因此,我们在这里得到的想法是您的网络连接(通道)工作不正常,并且队列管理器由于某种原因不喜欢它。接下来的事情就是像您一样查看队列管理器必须说些什么。在错误日志中,您说看到了:2/17/2014 14:41:51 - Process(3924.1) User(MUSR_MQADMIN) Program(runmqlsr.exe)
Host(PROGRAMMER1) Installation(Installation1)
VRMF(7.5.0.2)
AMQ6118: An internal WebSphere MQ error has occurred (20006047)
现在,这表明可能还剪切了一个FDC文件,该文件将提供更多详细信息,但是同样可以使用mqrc工具查找另一个错误代码。输入
mqrc 0x20006047
,它将报告:-536895559 0x20006047. xecX_E_CONV_NOT_SUP
这表明它无法处理客户端和队列管理器之间的数据转换。 FDC文件将为您提供更多详细信息。
关于java - MQ:与主机的连接被拒绝| channel 协商失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21830631/