How to check whether have message in the queue

眉间皱痕 提交于 2019-12-09 13:59:58

问题


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!

Thanks


回答1:


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

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);

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

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




回答2:


The answer didn't show how to check for MQRC_NO_MSG_AVAILABLE. Here is my solution. If there are better ones please let me know.

try
{
    queue.Get(queueMessage, opt);
    String sMessage = queueMessage.ReadString(queueMessage.DataLength);
}
catch (MQException err)
{
    if (err.ReasonCode.CompareTo(MQC.MQRC_NO_MSG_AVAILABLE) == 0)
        return true;
}



回答3:


For Windows machine It depends on where your queue manager is.

You could use MQUtilities - ih03 pack - which has rfhUtil.exe (Local Qm) and rfhUtilC.exe (for remote qm)

For Local QM , it is straight forward you need to place appropriate values and hit browse, it will show you Queue Depth.

For Remote QM, Place /TCP/(PortNo) for queue manager name and queue for queue name. Hit browse and you will get to know the queue depth.

For Unix/Ubuntu/Linux versions - There is a product called MQVisualEdit which is similar to this one.



来源:https://stackoverflow.com/questions/4679905/how-to-check-whether-have-message-in-the-queue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!