问题描述
- 问一个关于 IBM WebSphere MQ的问题,消息错误代码为RC2019
- 我写了一个生产者程序,每隔5s往MQ发100条消息,又写了一个消费者程序,每隔10s从MQ中取消息,再写入文件,
生产者MQ主要代码:
MQQueue queue = null;
int openOptions = MQConstants.MQOO_OUTPUT
| MQConstants.MQOO_FAIL_IF_QUIESCING
| MQConstants.MQGMO_WAIT;if (qMgr == null || !qMgr.isConnected()) { qMgr = new MQQueueManager(qmName); } try { queue = qMgr.accessQueue(qName openOptions); MQMessage putMessage = new MQMessage(); // putMessage.messageId = msgID.getBytes(); // putMessage.writeUTF(message); putMessage.write(message.getBytes(""UTF-8"")); MQPutMessageOptions pmo = new MQPutMessageOptions(); queue.put(putMessage pmo); queue.close(); } catch (Exception e) { e.printStackTrace(System.out); throw e; } finally { try { if (queue != null) { try { queue.close(); } catch (MQException e) { e.printStackTrace(); } } if (qMgr != null) { qMgr.disconnect(); } } catch (MQException e) { throw e; } } 消费者MQ主要代码: String[] messages = null; int count = 0; try { qMgr = new MQQueueManager(qmName); } catch (MQException e) { throw e; } // @SuppressWarnings(""deprecation"") // int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT // | MQC.MQOO_INQUIRE; // int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | // MQConstants.MQOO_OUTPUT; int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_INQUIRE ;
// | MQConstants.MQOO_FAIL_IF_QUIESCING;
MQQueue queue = null; try { queue = qMgr.accessQueue(qName openOptions null null null); int depth = queue.getCurrentDepth(); messages = new String[depth]; // System.out.println(""队列中的消息长度为:"" + depth); // 将队列中的消息读取出来 while (depth-- > 0) { // System.out.println(depth); MQMessage msg = new MQMessage();// 读取的队列消息 // msg.messageId = msgID.getBytes(); MQGetMessageOptions gmo = new MQGetMessageOptions(); queue.get(msg gmo); int len = msg.getDataLength(); byte[] buf = new byte[len]; msg.readFully(buf 0 len); String strmsgCont = new String(bufUTF-8""); messages[count++] = strmsgCont; } } catch (MQException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (queue != null) { try { queue.close(); } catch (MQException e) { e.printStackTrace(); } } if (qMgr != null) { qMgr.disconnect(); } } return messages;}
刚开始的几次,差不多20s内两边正常收发,之后就报了这个异常MQJE001: 完成代码为 '2',原因为 '2019'。
com.ibm.mq.MQException: MQJE001: 完成代码为 '2',原因为 '2019'。看了IBM的官方文档解释,也是一头雾水,麻烦谁知道的告诉一下;
注:附IBM官方接释:
2019 (07E3) (RC2019): MQRC_HOBJ_ERROR
Explanation
The object handle Hobj is not valid for one of the following reasons:
v The parameter pointer is not valid or (for the MQOPEN call) points to
read-only storage. (It is not always possible to detect parameter pointers that are
not valid; if not detected unpredictable results occur.)
v The value specified was not returned by a preceding MQOPEN call.
v The value specified has been made invalid by a preceding MQCLOSE call.
v The handle is a shared handle that has been made invalid by another thread
issuing the MQCLOSE call.
v The handle is a nonshared handle that is being used by a thread that did not
create the handle.
v The call is MQGET or MQPUT but the object represented by the handle is not a
queue.