永发信息网

mq java 怎么判断队列为空

答案:1  悬赏:50  手机版
解决时间 2021-03-20 06:41
  • 提问者网友:别再叽里呱啦
  • 2021-03-19 13:09
mq java 怎么判断队列为空
最佳答案
  • 五星知识达人网友:举杯邀酒敬孤独
  • 2021-03-19 13:48
MQException
该类包含WebSphere MQ 完成代码和错误代码常量的定义。以MQCC_开始的常量是WebSphere MQ 完成代码,而以MQRC_开始的常量则是WebSphere MQ 原因代码。只要出现WebSphere MQ
错误,就会给出MQException。
MQGetMessageOptions
该类包含控制MQQueue.get()方法行为的选项。
MQManagedObject
该类是MQQueueManager、MQQueue 和MQProcess 类的超类。它提供查询并设置这些资源属性的能力。

------解决方案--------------------
去取一次,得到 2033 错误就是没有消息符合你的条件。

使用 PCF 查询队列资料:


public QueueInfo queryQueueInfo() throws Exception {
if (!checkStatus2(this.queueManager)) {
throw new IllegalStateException("Not Connected to queue manager.");
}

PCFMessageAgent agent = null;

try {
agent = new PCFMessageAgent(this.queueManager);

// Inquiry Queue Name & Current Depth.
int[] attrs = {
CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH,
CMQC.MQIA_OPEN_INPUT_COUNT, CMQC.MQIA_OPEN_OUTPUT_COUNT,
CMQC.MQIA_Q_TYPE, CMQC.MQIA_DEFINITION_TYPE, CMQC.MQIA_INHIBIT_GET,
CMQC.MQIA_INHIBIT_PUT };

PCFParameter[] parameters = {
new MQCFST(CMQC.MQCA_Q_NAME , getInputQueue().getText().trim()),
new MQCFIL(CMQCFC.MQIACF_Q_ATTRS , attrs) };

// logger.log("Querying current depth of current queue.");
MQMessage[] responses = agent.send(CMQCFC.MQCMD_INQUIRE_Q, parameters);

QueueInfo info = new QueueInfo();

for (int i = 0; i < responses.length; i++) {
MQCFH cfh = new MQCFH(responses[i]);

// Check the PCF header (MQCFH) in the response message

if (cfh.reason == 0) {
String name = "";
Integer depth = new Integer(0);

for (int j = 0; j < cfh.parameterCount; j++) { // Extract what we want from the returned attributes

PCFParameter p = PCFParameter.nextParameter(responses[i]);

switch (p.getParameter()) {
case CMQC.MQCA_Q_NAME:
name = (String) p.getValue();
info.name = name;
break;
case CMQC.MQIA_CURRENT_Q_DEPTH:
depth = (Integer) p.getValue();
info.depth = depth.intValue();
break;
case CMQC.MQIA_OPEN_INPUT_COUNT:
Integer inputCount = (Integer) p.getValue();
info.inputCount = inputCount.intValue();
break;
case CMQC.MQIA_OPEN_OUTPUT_COUNT:
Integer outputCount = (Integer) p.getValue();
info.outputCount = outputCount.intValue();
break;
case CMQC.MQIA_Q_TYPE:
info.type = ((Integer) p.getValue()).intValue();
break;
case CMQC.MQIA_DEFINITION_TYPE:
info.definitionType = ((Integer) p.getValue()).intValue();
break;
case CMQC.MQIA_INHIBIT_PUT:
info.putNotAllowed = ((Integer) p.getValue()).intValue() == 1;
break; case CMQC.MQIA_INHIBIT_GET:
info.getNotAllowed = ((Integer) p.getValue()).intValue() == 1;
default:
}
}

// System.out.println("Queue " + name + " curdepth " + depth);

return info;

} else {
System.out.println("PCF error:\n" + cfh);

// Walk through the returned parameters describing the error

for (int j = 0; j < cfh.parameterCount; j++) {
System.out.println(PCFParameter.nextParameter(responses[0]));
}

throw new Exception("PCF Error [reason :" + cfh.reason + "]");
}
}

return null;

} catch (Exception e) {
throw e;
} finally {
if (agent != null) {
try {
agent.disconnect();
} catch (Exception e) {
logger.log(e);
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯