Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
667 views
in Technique[技术] by (71.8m points)

java - Check MQ queue depth

Can anyone help in doing the code in java of getting the depth of the queues. We are having 4 queues in IBM WebSphere MQ and inside them there are messages.

I want to write a jsp to read the queue names and their depth while running the report. How do I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See http://blog.guymahieu.com/2008/06/11/getting-the-depth-of-an-mqseries-queue-from-java/.

I re-implemented this as follows:

import com.ibm.mq.*;

public class QueueManager {

    private final String host;
    private final int port;
    private final String channel;
    private final String manager;
    private final MQQueueManager qmgr;

    public QueueManager(String host, int port, String channel, String manager) throws MQException {
        this.host = host;
        this.port = port;
        this.channel = channel;
        this.manager = manager;
        this.qmgr = createQueueManager();
    }

    public int depthOf(String queueName) throws MQException {
        MQQueue queue = qmgr.accessQueue(queueName, MQC.MQOO_INQUIRE | MQC.MQOO_INPUT_AS_Q_DEF, null, null, null);
        return queue.getCurrentDepth();
    }

    @SuppressWarnings("unchecked")
    private MQQueueManager createQueueManager() throws MQException {
        MQEnvironment.channel = channel;
        MQEnvironment.port = port;
        MQEnvironment.hostname = host;
        MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
        return new MQQueueManager(manager);
    }
}

Put the following jars on your classpath:

  • com.ibm.mq*jar
  • j2ee.jar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...