IBM MQ Monitor

来源:互联网 发布:163k门户系统源码 x6 编辑:程序博客网 时间:2024/05/21 00:18

通过MQQueueManager获取所有的Queue列表,采用命令行的方式


package com.iss.ibm.monitor;


import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.CMQCFC;
import com.ibm.mq.pcf.PCFMessage;
import com.ibm.mq.pcf.PCFMessageAgent;

@SuppressWarnings("deprecation")
public class QueueManagerMonitor
{
    private        String        host;
    private        Integer        port;
    private        String        transport = "MQSeries";
    private        String        channel = "SYSTEM.DEF.SVRCONN";
    private        Integer        CCSID = 950;
    private        String        username;
    private        String        password;
    
    public QueueManagerMonitor(String host, Integer port, String username,
            String password, String qMName) {
        super();
        this.host = host;
        this.port = port;
        this.username = username;
        this.password = password;
        this.qMName = qMName;
    }

    private        String        qMName    =    "QM_S11101";
    
    /**
     * 获取MQQueueManager对象
     * @author 王成(chengwangi@isoftstone.com)
     * @date 2012-11-16 上午10:01:13
     * @return
     * @throws MQException
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public MQQueueManager getQueueManager() throws MQException
    {
        Hashtable properties = new Hashtable();
        properties.put("hostname", host);
        properties.put("transport", transport);
        properties.put("channel", channel);
        properties.put("port", port);
        properties.put("CCSID", CCSID);
        properties.put("username", username);
        properties.put("password", password);
        return new MQQueueManager(qMName, properties);
    }
    /**
     * 通过MQQueueManager获取其下所有Queue的名称     
     * @author 王成(chengwangi@isoftstone.com)
     * @date 2012-11-16 上午10:01:25
     * @param qManager
     * @return
     * @throws MQException
     * @throws IOException
     */
    public List<String> getQueueNames(MQQueueManager qManager) throws MQException, IOException
    {
        List<String> qNames = new ArrayList<String>();
        
        PCFMessageAgent agent = new PCFMessageAgent(qManager);
        PCFMessage   request = new PCFMessage (CMQCFC.MQCMD_INQUIRE_Q_NAMES);
        request.addParameter (CMQC.MQCA_Q_NAME, "*");
        request.addParameter (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL);
        PCFMessage []   responses = agent.send (request);
        String []   names = (String []) responses [0].getParameterValue (CMQCFC.MQCACF_Q_NAMES);
        
        for (int i = 0; i < names.length; i++)
        {
            qNames.add(names[i]);
        }
        return qNames;
    }
    
}


原创粉丝点击