Websphere 7 SIB队列:如何从Java访问队列深度?

时间:2011-11-16 13:20:55

标签: java websphere mq

我已经创建了一些代码来访问Websphere MQ的队列深度,但是如果有用于访问SIB队列的API,或者我可以设置websphere以允许我访问它,我就无法解决。< / p>

有人能给我一些提示/想法吗?

由于 杰夫波特

1 个答案:

答案 0 :(得分:1)

答案,对于那些关心的人。

好的,所以我没有设法让WSADMIN使用的API工作,但我已经使用SOAP直接进入websphere来询问队列。

注意:默认端口为8880

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;

import javax.management.ObjectName;

import org.apache.log4j.Logger;

import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;

 <SNIP>
 Properties connectProps = new Properties();
 connectProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
 connectProps.setProperty(AdminClient.CONNECTOR_HOST, "127.0.0.1");
 connectProps.setProperty(AdminClient.CONNECTOR_PORT, "8880"); 

 AdminClient adminClient = null;
    try
    {
      adminClient = AdminClientFactory.createAdminClient(connectProps);

      Set<ObjectName> s2 = adminClient.queryNames(new ObjectName("WebSphere:*"), null);
      if (!s2.isEmpty())
      {
        Iterator<ObjectName> i = s2.iterator();
        while (i.hasNext())
        {
          ObjectName on = i.next();
          String type = on.getKeyProperty("type");
          if ("SIBQueuePoint".equals(type))
          {
            String queueName = on.getKeyProperty("name") ;
            int currentDepth =  ((Integer) adminClient.getAttribute(on, "depth")).intValue();
            int maxSize =  ((Integer) adminClient.getAttribute(on, "highMessageThreshold")).intValue();

            LOG.info("Queried SIB queue: Queue: [" + queueName + "] Size =[" + currentDepth + "] highMessageThreshold:["+maxSize+"]");
          }
        }
      }
      else {
        System.out.println("MBean was not found");
      }
    }
    catch (Exception e)
    {
      LOG.error("Error finding SIB queue details, message:" + e.getMessage(), e); 
    }