mq java 如何判断队列为空

zj2973230 2010-04-27 07:57:48
有什么有关mq的函数吗?
...全文
442 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
humanity 2010-09-08
  • 打赏
  • 举报
回复
去取一次,得到 2033 错误就是没有消息符合你的条件。

使用 PCF 查询队列资料:

/**
* @return current depth of queue connected currently.
* @throws Exception
*/
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);
}
}
}
}
yingwuluohan 2010-09-08
  • 打赏
  • 举报
回复

MQException
该类包含WebSphere MQ 完成代码和错误代码常量的定义。以MQCC_开始的常量是WebSphere MQ 完成代码,而以MQRC_开始的常量则是WebSphere MQ 原因代码。只要出现WebSphere MQ
错误,就会给出MQException。
MQGetMessageOptions
该类包含控制MQQueue.get()方法行为的选项。
MQManagedObject
该类是MQQueueManager、MQQueue 和MQProcess 类的超类。它提供查询并设置这些资源属性的能力。
yingwuluohan 2010-09-08
  • 打赏
  • 举报
回复
MQChannelDefinition
该类用来传递有关连接队列管理器的信息至发送、接收和安全退出。当以绑定模式直接连接到WebSphere MQ时,此类不适用。
MQChannelExit
当调用发送、接收和安全退出时,该类定义传递到这些调用的上下文信息。该类的exitResponse 属性应当通过退出设置,以显示WebSphere MQ Client for Java 下一步应当采取何
种行动。

2,633

社区成员

发帖
与我相关
我的任务
社区描述
WebSphere 是 IBM 的软件平台。它包含了编写、运行和监视全天候的工业强度的随需应变 Web 应用程序和跨平台、跨产品解决方案所需要的整个中间件基础设施,如服务器、服务和工具。
社区管理员
  • WebSphere社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧