当我执行下面的代码时,出现以下错误。你能告诉我为什么吗?这听起来问题在于频道,但我验证了,但我没有找出问题的原因。我在网上尝试了很多例子,但这个问题仍然存在。
import java.io.IOException;
import java.util.Hashtable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ibm.mq.MQAsyncStatus;
import com.ibm.mq.MQException;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.MQConstants;
public class MQClientTest2 {
private static final Logger LOGGER = LoggerFactory.getLogger(MQClientTest.class);
public static void main(String args[]) {
// Create a connection to the queue manager
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put(MQConstants.CHANNEL_PROPERTY, "WM.SVRCONN.001");
props.put(MQConstants.PORT_PROPERTY, 1414);
props.put(MQConstants.HOST_NAME_PROPERTY, "localhost");
String qManager = "QM1";
String queueName = "LQ1";
MQQueueManager qMgr = null;
try {
qMgr = new MQQueueManager(qManager, props);
// MQOO_OUTPUT = Open the queue to put messages. The queue is opened for use with subsequent MQPUT calls.
// MQOO_INPUT_AS_Q_DEF = Open the queue to get messages using the queue-defined default.
// The queue is opened for use with subsequent MQGET calls. The type of access is either
// shared or exclusive, depending on the value of the DefInputOpenOption queue attribute.
int openOptions = MQConstants.MQOO_OUTPUT | MQConstants.MQOO_INPUT_AS_Q_DEF;
// creating destination
MQQueue queue = qMgr.accessQueue(queueName, openOptions);
// specify the message options...
MQPutMessageOptions pmo = new MQPutMessageOptions(); // default
// MQPMO_ASYNC_RESPONSE = The MQPMO_ASYNC_RESPONSE option requests that an MQPUT or MQPUT1 operation
// is completed without the application waiting for the queue manager to complete the call.
// Using this option can improve messaging performance, particularly for applications using client bindings.
pmo.options = MQConstants.MQPMO_ASYNC_RESPONSE;
// create message
MQMessage message = new MQMessage();
// MQFMT_STRING = The application message data can be either an SBCS string (single-byte character set),
// or a DBCS string (double-byte character set). Messages of this format can be converted
// if the MQGMO_CONVERT option is specified on the MQGET call.
message.format = MQConstants.MQFMT_STRING;
message.writeString("<message>Hallo Vinh</message>");
queue.put(message, pmo);
queue.close();
MQAsyncStatus asyncStatus = qMgr.getAsyncStatus();
System.out.println("valor do asyncStatus: " + asyncStatus.putSuccessCount);
} catch (MQException e) {
LOGGER.error("Die Verbindung zum Message Broker mit den "
+ "Eigenschaften {} und dem QueueManager {} konnte nicht hergestellt werden.", props, qManager, e);
} catch (IOException e) {
LOGGER.error("Fehler beim Schreiben der Message.", e);
} finally {
try {
qMgr.disconnect();
} catch (MQException e) {
LOGGER.error("Die Verbindung konnte nicht geschlossen werden.", e);
}
}
}
}
这是执行程序时发生的错误:
23:47:34.255 [main] ERROR com.mkyong.MQClientTest - Die Verbindung zum Message Broker mit den Eigenschaften {hostname=localhost, port=1414, channel=WM.SVRCONN.001} und dem QueueManager QM1 konnte nicht hergestellt werden.
com.ibm.mq.MQException: MQJE001: Código de Conclusão '2', Razão '2540'.
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:255)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:97)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:874)
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:822)
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:764)
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:979)
at com.mkyong.MQClientTest2.main(MQClientTest2.java:33)
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2540;AMQ9204: Conexão com o host 'localhost(1414)' rejeitada. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2540;AMQ9520: Canal não definido remotamente. [3=WM.SVRCONN.001 ]],3=localhost(1414),5=RemoteConnection.analyseErrorSegment]
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:2314)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1285)
at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:377)
at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:562)
at com.ibm.mq.MQSESSION.MQCONNX_j(MQSESSION.java:916)
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:240)
... 10 common frames omitted
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2540;AMQ9520: Canal não definido remotamente. [3=WM.SVRCONN.001 ]
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.analyseErrorSegment(RemoteConnection.java:4464)
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.receiveTSH(RemoteConnection.java:3199)
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.initSess(RemoteConnection.java:1274)
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:895)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:416)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:312)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:146)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1761)
... 15 common frames omitted
Exception in thread "main" java.lang.NullPointerException
at com.mkyong.MQClientTest2.main(MQClientTest2.java:71)
下面我从我配置频道的地方放置了图像。
删除所有队列管理器并重新创建新队列管理器后,我收到了这个新错误:
com.ibm.mq.MQException: MQJE001: Código de Conclusão '2', Razão '2035'.
at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:255)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11._createManagedConnection(MQClientManagedConnectionFactoryJ11.java:450)
at com.ibm.mq.MQClientManagedConnectionFactoryJ11.createManagedConnection(MQClientManagedConnectionFactoryJ11.java:487)
at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:97)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:194)
at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:874)
at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:822)
at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:764)
at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:200)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:979)
at com.mkyong.MQClientTest2.main(MQClientTest2.java:33)
Exception in thread "main" java.lang.NullPointerException
at com.mkyong.MQClientTest2.main(MQClientTest2.java:73)
我安装IBM MQ的目录:
执行命令set | findstr MQ后:
Classpath=C:\LINGO64_17\Lingo17.jar;C:\Program Files\IBM\MQ\java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\MQ\java\lib\com.ibm.mq.jar
CP=D:\rabbitMQ
INCLUDE=C:\Program Files\IBM\MQ\tools\c\include;C:\Program Files\IBM\MQ\tools\cplus\include
LIB=C:\Program Files\IBM\MQ\tools\lib64;C:\Program Files\IBM\MQ\tools\lib
MQ_FILE_PATH=C:\Program Files\IBM\MQ
MQ_JAVA_DATA_PATH=C:\ProgramData\IBM\MQ
MQ_JAVA_INSTALL_PATH=C:\Program Files\IBM\MQ\java
MQ_JAVA_LIB_PATH=C:\Program Files\IBM\MQ\java\lib64;C:\Program Files\IBM\MQ\java\lib
MQ_JRE_PATH=C:\Program Files\IBM\MQ\java\jre
Path=C:\Program Files\IBM\MQ\java\lib;C:\Program Files\IBM\MQ\java\lib64;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\PostgreSQL\pg95\bin;C:\Program Files\Java\jdk1.8.0_131\bin;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\drivers;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\jre\bin;C:\Program Files\Progress\DataDirect\Connect64_for_ODBC_71\jre\bin\server;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\LINGO64_17\;C:\Program Files\nodejs\;C:\PostgreSQL\pg96\bin;C:\Program Files\IBM\MQ\bin64;C:\Program Files\IBM\MQ\bin;C:\Program Files\IBM\MQ\tools\c\samples\bin64;C:\Program Files\IBM\MQ\tools\c\samples\bin;C:\Users\camar\AppData\Local\Microsoft\WindowsApps;C:\Users\camar\AppData\Roaming\npm;C:\Program Files\nodejs;
答案 0 :(得分:0)
MQJE001:CódigodeConclusão'2',Razão'2540'。
您是否查找了原因代码2540?所有MQ原因代码都记录在MQ Knowledge中。这是2540 (MQRC_UNKNOWN_CHANNEL_NAME)
的RC以下是包含所有MQ Reason Codes。
的页面在您的示例中,您使用了端口#1414,但您的PC上有3个队列管理器。您可能连接到错误的端口,因此队列管理器错误。如果您不记得为队列管理器设置的端口号,那么您只需单击“监听器”,然后查看“LISTENER.TCP”对象用于该特定队列管理器的端口号。每个队列管理器都需要一个UNIQUE端口#。
所以基本上,当你没有注意到你正在做的事情时,你会通过删除你的队列管理员来解雇自己。
MQJE001:CódigodeConclusão'2',Razão'2035'。
您是否查找了原因代码2035?这是2035 (MQRC_NOT_AUTHORIZED)
的RC您是否使用正确的端口#作为新队列管理器?您是否在新队列管理器中创建了频道?您是否正在使用SYSTEM。*频道或在'mqm'组中使用UserId运行,因为CHLAUTH止回规则可能会阻止您。阅读Morag关于CHLAUTH止回规则的帖子: