Ibm mq 异常:com.ibm.mq.MQException:MQJE001:完成代码2,原因2009
我正在尝试将测试消息写入MQ,但失败 共享源代码和错误: 源代码Ibm mq 异常:com.ibm.mq.MQException:MQJE001:完成代码2,原因2009,ibm-mq,Ibm Mq,我正在尝试将测试消息写入MQ,但失败 共享源代码和错误: 源代码 import com.ibm.mq.MQEnvironment; import com.ibm.mq.MQMessage; import com.ibm.mq.MQPutMessageOptions; import com.ibm.mq.MQQueueManager; import com.ibm.mq.MQQueue; import com.ibm.mq.MQC; public class MQResponseWriter {
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQC;
public class MQResponseWriter {
public static void main(String[] args) {
try {
int openOptions = MQC.MQOO_INQUIRE | MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQEnvironment.hostname = "myserver_name";
MQEnvironment.port = 1417;
MQEnvironment.channel = "my_channel_name";
//MQEnvironment.properties.put(CMQC.USER_ID_PROPERTY, "admin");
//MQEnvironment.properties.put(CMQC.PASSWORD_PROPERTY, "passw0rd");
//MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQQueueManager queueManager;
queueManager = new MQQueueManager("queue_manger_name");
MQQueue destQueue = queueManager.accessQueue("queue_name", openOptions);
MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Blah...blah...bleah...test message no.1...!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
destQueue.put(hello_world, pmo);
destQueue.close();
queueManager.disconnect();
System.out.println("------------------------success...");
} catch (Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
}
}
}
MQJE001: An MQException occurred: Completion Code 2, Reason 2195
MQJE007: IO error reading message data
Error occured during API call - reason code0
MQJE001: Completion Code 2, Reason 2009
MQJE001: Completion Code 2, Reason 2018
Exception: com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:922)
at com.ibm.mq.MQManagedConnectionJ11.getConnection(MQManagedConnectionJ11.java:426)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:180)
at com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:771)
at com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:705)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:434)
at com.module.main.MQResponseWriter.main(MQResponseWriter.java:24)
错误消息
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQC;
public class MQResponseWriter {
public static void main(String[] args) {
try {
int openOptions = MQC.MQOO_INQUIRE | MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQEnvironment.hostname = "myserver_name";
MQEnvironment.port = 1417;
MQEnvironment.channel = "my_channel_name";
//MQEnvironment.properties.put(CMQC.USER_ID_PROPERTY, "admin");
//MQEnvironment.properties.put(CMQC.PASSWORD_PROPERTY, "passw0rd");
//MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQQueueManager queueManager;
queueManager = new MQQueueManager("queue_manger_name");
MQQueue destQueue = queueManager.accessQueue("queue_name", openOptions);
MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Blah...blah...bleah...test message no.1...!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
destQueue.put(hello_world, pmo);
destQueue.close();
queueManager.disconnect();
System.out.println("------------------------success...");
} catch (Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
}
}
}
MQJE001: An MQException occurred: Completion Code 2, Reason 2195
MQJE007: IO error reading message data
Error occured during API call - reason code0
MQJE001: Completion Code 2, Reason 2009
MQJE001: Completion Code 2, Reason 2018
Exception: com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2009
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:922)
at com.ibm.mq.MQManagedConnectionJ11.getConnection(MQManagedConnectionJ11.java:426)
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:180)
at com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:771)
at com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:705)
at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:434)
at com.module.main.MQResponseWriter.main(MQResponseWriter.java:24)
MQJE001:发生MQException:完成代码2,原因2195
MQJE007:读取消息数据时发生IO错误
API调用期间出错-原因代码0
MQJE001:完成代码2,原因2009
MQJE001:完成代码2,原因2018
异常:com.ibm.mq.MQException:MQJE001:完成代码2,原因2009
com.ibm.mq.MQException:MQJE001:完成代码2,原因2009
位于com.ibm.mq.MQQueueManager。(MQQueueManager.java:922)
位于com.ibm.mq.MQManagedConnectionJ11.getConnection(MQManagedConnectionJ11.java:426)
位于com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:180)
位于com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:771)
位于com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:705)
位于com.ibm.mq.MQQueueManager。(MQQueueManager.java:434)
位于com.module.main.MQResponseWriter.main(MQResponseWriter.java:24)
上述错误的主要原因是什么?如果有,解决方案是什么???我不知道需要在@StackOverflow发布多少次,但不要使用MQEnvironment类,因为它不是线程安全的。改用哈希表。以下是一个工作示例:
import java.io.IOException;
import java.util.Hashtable;
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.CMQC;
/**
* Program Name
* MQTest11
*
* Description
* This java class will connect to a remote queue manager with the
* MQ setting stored in a HashTable and put a message to a queue.
*
* Sample Command Line Parameters
* -m MQA1 -h 127.0.0.1 -p 1414 -c TEST.CHL -q TEST.Q1 -u UserID -x Password
*
* @author Roger Lacroix
*/
public class MQTest11
{
private Hashtable<String,String> params;
private Hashtable<String,Object> mqht;
private String qManager;
private String outputQName;
/**
* The constructor
*/
public MQTest11()
{
super();
params = new Hashtable<String,String>();
mqht = new Hashtable<String,Object>();
}
/**
* Make sure the required parameters are present.
* @return true/false
*/
private boolean allParamsPresent()
{
boolean b = params.containsKey("-h") && params.containsKey("-p") &&
params.containsKey("-c") && params.containsKey("-m") &&
params.containsKey("-q") &&
params.containsKey("-u") && params.containsKey("-x");
if (b)
{
try
{
Integer.parseInt((String) params.get("-p"));
}
catch (NumberFormatException e)
{
b = false;
}
}
return b;
}
/**
* Extract the command-line parameters and initialize the MQ HashTable.
* @param args
* @throws IllegalArgumentException
*/
private void init(String[] args) throws IllegalArgumentException
{
int port = 1414;
if (args.length > 0 && (args.length % 2) == 0)
{
for (int i = 0; i < args.length; i += 2)
{
params.put(args[i], args[i + 1]);
}
}
else
{
throw new IllegalArgumentException();
}
if (allParamsPresent())
{
qManager = (String) params.get("-m");
outputQName = (String) params.get("-q");
try
{
port = Integer.parseInt((String) params.get("-p"));
}
catch (NumberFormatException e)
{
port = 1414;
}
mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));
mqht.put(CMQC.PORT_PROPERTY, new Integer(port));
mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));
// I don't want to see MQ exceptions at the console.
MQException.log = null;
}
else
{
throw new IllegalArgumentException();
}
}
/**
* Connect, open queue, write a message, close queue and disconnect.
*
* @throws MQException
*/
private void testSend()
{
MQQueueManager qMgr = null;
MQQueue queue = null;
String line;
int openOptions = CMQC.MQOO_OUTPUT + CMQC.MQOO_FAIL_IF_QUIESCING;
MQPutMessageOptions pmo = new MQPutMessageOptions();
try
{
qMgr = new MQQueueManager(qManager, mqht);
System.out.println("MQTest11 successfully connected to "+ qManager);
queue = qMgr.accessQueue(outputQName, openOptions);
System.out.println("MQTest11 successfully opened "+ outputQName);
// Define a simple MQ message, and write some text in UTF format..
MQMessage sendmsg = new MQMessage();
sendmsg.format = CMQC.MQFMT_STRING;
sendmsg.feedback = CMQC.MQFB_NONE;
sendmsg.messageType = CMQC.MQMT_DATAGRAM;
line = "This is a test message embedded in the MQTest11 program.";
sendmsg.messageId = CMQC.MQMI_NONE;
sendmsg.correlationId = CMQC.MQCI_NONE;
sendmsg.writeString(line);
// put the message on the queue
queue.put(sendmsg, pmo);
System.out.println("Message Data>>>" + line);
}
catch (MQException e)
{
System.out.println("MQTest11 cc=" +e.completionCode + " : rc=" + e.reasonCode);
}
catch (IOException e)
{
System.out.println("MQTest11 IOException:" +e.getLocalizedMessage());
}
finally
{
try
{
queue.close();
System.out.println("MQTest11 closed: "+ outputQName);
}
catch (MQException e)
{
System.out.println("MQTest11 cc=" +e.completionCode + " : rc=" + e.reasonCode);
}
try
{
qMgr.disconnect();
System.out.println("MQTest11 disconnected from "+ qManager);
}
catch (MQException e)
{
System.out.println("MQTest11 cc=" +e.completionCode + " : rc=" + e.reasonCode);
}
}
}
/**
* main line
* @param args
*/
public static void main(String[] args)
{
MQTest11 write = new MQTest11();
try
{
write.init(args);
write.testSend();
}
catch (IllegalArgumentException e)
{
System.err.println("Usage: java MQTest11 -m QueueManagerName -h host -p port -c channel -q QueueName -u UserID -x Password");
System.exit(1);
}
System.exit(0);
}
}
import java.io.IOException;
导入java.util.Hashtable;
导入com.ibm.mq.MQException;
导入com.ibm.mq.MQMessage;
导入com.ibm.mq.MQPutMessageOptions;
导入com.ibm.mq.MQQueue;
导入com.ibm.mq.MQQueueManager;
导入com.ibm.mq.constants.CMQC;
/**
*程序名
*MQTest11
*
*描述
*此java类将使用连接到远程队列管理器
*MQ设置存储在哈希表中,并将消息放入队列。
*
*命令行参数示例
*-MQA1-h127.0.0.1-p1414-c TEST.CHL-q TEST.Q1-u UserID-x Password
*
*@作者罗杰·拉克鲁瓦
*/
公共类MQTest11
{
私有哈希表参数;
私有哈希表mqht;
私有字符串管理器;
私有字符串outputQName;
/**
*构造器
*/
公共MQTest11()
{
超级();
params=新哈希表();
mqht=新哈希表();
}
/**
*确保存在所需的参数。
*@return-true/false
*/
私有布尔allParamsPresent()
{
布尔b=params.containsKey(“-h”)和¶ms.containsKey(“-p”)&&
参数containsKey(“-c”)&参数containsKey(“-m”)&&
参数containsKey(“-q”)&&
参数containsKey(“-u”)和参数containsKey(“-x”);
如果(b)
{
尝试
{
Integer.parseInt((String)params.get(“-p”);
}
捕获(数字格式)
{
b=假;
}
}
返回b;
}
/**
*提取命令行参数并初始化MQ哈希表。
*@param args
*@galargumentException
*/
私有void init(字符串[]args)引发IllegalArgumentException
{
int端口=1414;
如果(args.length>0&(args.length%2)==0)
{
对于(int i=0;i>>”+行);
}
捕获(MQE异常)
{
System.out.println(“MQTest11 cc=“+e.completionCode+”:rc=“+e.reasonCode”);
}
捕获(IOE异常)
{
System.out.println(“MQTest11 IOException:+e.getLocalizedMessage());
}
最后
{
尝试
{
queue.close();
System.out.println(“MQTest11关闭:“+outputQName”);
}
捕获(MQE异常)
{
System.out.println(“MQTest11 cc=“+e.completionCod