I am working on a monitor application for some IBM MQ queues. I am trying to implement a way in which I can transfer all messages from one queue to another. Will the get(msg) method remove a message from the queue? Or will it just retrieve a copy of it?

Here is my code:

private void moveMessages(String qName, String moveToThisQ) {
    try {
        MQQueue q = qm.accessQueue(qName, MQConstants.MQOO_INQUIRE);
        MQQueue qMoveHere = qm.accessQueue(moveToThisQ,
                MQConstants.MQOO_INQUIRE);
        while (q.getCurrentDepth() != 0) {
            MQMessage msg = new MQMessage();
            q.get(msg);
            qMoveHere.put(msg);
        }
        if (q != null)
            q.close();
        if (qMoveHere != null)
            qMoveHere.close();
    } catch (MQException e) {
        e.printStackTrace();
    }
}

If anyone could offer any insight as tho the effects of the get(msg) will have on the queue? From the examples I've looked at, I might have to pass an option along with the get method? maybe not?!

有帮助吗?

解决方案 2

Yes. get() removes the message from the queue unless you have specified MQConstants.MQOO_BROWSE in the accessQueue() method.

API documentation below. Look for openOptionsArg in the accessQueue() method. http://pic.dhe.ibm.com/infocenter/wmqv7/v7r5/index.jsp?topic=%2Fcom.ibm.mq.javadoc.doc%2FWMQJavaClasses%2Fcom%2Fibm%2Fmq%2FMQQueueManager.html

其他提示

while (q.getCurrentDepth() != 0)

Never ever do this in MQ. A message could be on the queue but not available to your application yet and yes, current depth would be greater than 1.

Also, doing what you are doing will not keep the information in the MQMD header. Most fields will be re-initialized on the put call. Go look up MQOO_PASS_ALL_CONTEXT and MQOO_SAVE_ALL_CONTEXT in the manual.

Can you provide little more details on what you are trying to monitor? WebSphere MQ already provides ways to monitor queues, for example you can monitor queue depth high/low/full, accounting and statistics etc. You can use the existing monitoring features instead of writing your own if those are the ones you are looking for.

You can find detailed description here on WebSphere MQ monitoring.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top