
正文
mq队列java代码 mq队列命令
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
在JAVA开发中,如何查询MQ中的队列句柄状态?
你用的是IBM MQ还是Apache的? 一般通过JAVA的JMS可以取得。
例如IBM MQ里有个MQQueue 对象
// 获取队列实例
MQQueue queue = qMgr.accessQueue("TEST_QUEUE", openOptions);
//获取当前队列最长消息的长度
queue.getMaximumMessageLength()
//获取当前队列最长深度
queue.getMaximumMessageLength()
等等功能都是提供的,具体你下载个WebSphere MQ API 找到MQQueue一看便知。
相关问答
Q1: 用java连接MQ时,如何获得某一个队列管
我用的方法是:
MQQueueManager qMgr = new MQQueueManager("BVMTEST");
System.out.println("queue manager is connected!");
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
/* 打开队列 */
com.ibm.mq.MQQueue queue = qMgr.accessQueue("test1", openOptions);
然后在调用queue.getCurrentDepth()的方法的时候居然报了异常:
MQJE001: 完成代码是 2,原因为 2038
如果我不在此处调用这个方法,而在后面进行
queue.put(outMsg, new MQPutMessageOptions());方法,居然可以成功放入测试信息.
给你一个有用的代码大全:
密码:exn4
Q2: Java 开源消息队列ActiveMQ等
你这个Queue是一个在内存里的数据结构类,提供了入队出队方法。实例化以后可以使用。
MessageQueue是一个Java的协议,是基于标准的,ActiveMQ是这个协议标准的具体实现。这个队列具有MessageQueue的通用功能,例如支持:发布者-订阅者,点到点的多种方式。用于SOA的大型分布式环境,12306抢票的时候你看见有多少人排队等待,就是使用的这个。
12306的后台服务器是分布式的,比如接受订票功能有100台服务器,一个LinkedBlockingQueue的范围只是一台机器,这样的话就会出现多个队,而且功能单一。这时候就会把订票请求发送给MessageQueue ,这个东西是分布式、异步的。。。。是完全不同的两个东西,没有可比性
Q3: 请问用java连接MQ时,如何获得某一个队列管理器下所有队列名称。
引起这个问题一个很有可能的原因是队列管理器在不正常停止后,虽然ps -ef | grep mq看不到此队列管理器的进程,但此MQ队列管理器的进程占用的信号灯和共享内存却没有被释放掉。解决办法如下:
1. 先查看是否有此队列管理器残留的 信号灯和共享内存。命令如下:
ipcs -a | grep mq
2. 如果有,使用ipcrm命令清除 残留的信号灯和共享内存,命令如下:
ipcrm -s semphore id
ipcrm -m shared memory id
3. 再次启动MQ队列管理器
Q4: 请问,java高手,有精通阿里云Mq消息队列的吗?
非也,我精通阿里云的MQ,从开始我就在用。
在Java后台代码,有生产者和消费者,也就是消费者和生产者都在后端,非JS什么的。
最好的实现方式你看阿里MQ的Spring集成方式。创建生产者,然后创建消费者,当然,生产者和消费者可以分开实现。消费者可以N个,生产者也可以N个,达到均衡和分布式的效果!
Q5: mq java 怎么判断队列为空
MQException
该类包含WebSphere MQ 完成代码和错误代码常量的定义。以MQCC_开始的常量是WebSphere MQ 完成代码,而以MQRC_开始的常量则是WebSphere MQ 原因代码。只要出现WebSphere MQ
错误,就会给出MQException。
MQGetMessageOptions
该类包含控制MQQueue.get()方法行为的选项。
MQManagedObject
该类是MQQueueManager、MQQueue 和MQProcess 类的超类。它提供查询并设置这些资源属性的能力。
------解决方案--------------------
去取一次,得到 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);
}
}
}
关于mq队列java代码和mq队列命令的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






