如何检查队列中是否有消息 [英] How to check whether have message in the queue

查看:260
本文介绍了如何检查队列中是否有消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IBM Websphere MQ.我有队列管理器和队列名称.现在,我要检查队列中是否有任何消息?

I am using IBM Websphere MQ. I have the queue manager and queue name. Now, I want to check whether the queue has any messages in it?

我以前没有做过这项工作.求助

I did not work on this before. Pleas help

如果您需要更多信息,请告诉我!

Please let me know if you need further information!

谢谢

推荐答案

下面的代码是.NET/amqmdnet-但您可以同时尝试进行转换,直到Java开发人员看到您的帖子为止.

The below code is .NET / amqmdnet - but you might try and convert this in the meantime until a Java dev sees your post.

要查看队列中是否有消息,而无需实际将其从队列中取出,请在队列上使用MQC.MQOO_BROWSE,并选择IBM.WMQ.MQC.MQGMO_BROWSE_FIRST 如果队列为空,您将得到MQRC_NO_MSG_AVAILABLE.

To see if there is a message on the queue, without actually taking it off the queue, use MQC.MQOO_BROWSE on the Queue and IBM.WMQ.MQC.MQGMO_BROWSE_FIRST as the option You'll get MQRC_NO_MSG_AVAILABLE if the queue is empty.

MQMessage queueMessage = new MQMessage();

MQQueueManager queueManager = new MQQueueManager(qmName, channelName, connName);
MQQueuequeue = queueManager.AccessQueue(qName, 
    MQC.MQOO_BROWSE + MQC.MQOO_FAIL_IF_QUIESCING);

MQGetMessageOptions opt = new MQGetMessageOptions();
opt.Options = IBM.WMQ.MQC.MQGMO_BROWSE_FIRST;
queueMessage.CorrelationId = IBM.WMQ.MQC.MQMI_NONE;
queueMessage.MessageId = IBM.WMQ.MQC.MQMI_NONE;
queue.Get(queueMessage, opt);
String sMessage = queueMessage.ReadString(queueMessage.DataLength);

要查看下一条消息,请使用IBM.WMQ.MQC.MQGMO_BROWSE_NEXT;

To peek the next message use IBM.WMQ.MQC.MQGMO_BROWSE_NEXT;

要真正从队列中读取消息,请在AccessQueue上使用MQC.MQOO_INPUT_SHARED.

To actually read the message OFF the queue, use MQC.MQOO_INPUT_SHARED on the AccessQueue.

这篇关于如何检查队列中是否有消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆