小编典典

如何从Weblogic的jms模块的资源摘要表中获取jms队列列表?

jsp

我需要打印jms模块的jms队列列表。我使用此代码查找所需的队列并获取参数,但是如何获取所有队列的名称并打印它们呢?

Properties env = new Properties();
    env.put(Context.PROVIDER_URL, "host:port");
    env.put(Context.SECURITY_PRINCIPAL, "username");
    env.put(Context.SECURITY_CREDENTIALS, "password");
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    InitialContext ctx = new InitialContext(env);
    Destination queue = (Destination) ctx.lookup("jms_queue");
    JMSDestinationRuntimeMBean destMBean = JMSRuntimeHelper.getJMSDestinationRuntimeMBean(ctx, queue);
    out.println("count: " + destMBean.getMessagesCurrentCount());

阅读 356

收藏
2020-06-08

共1个答案

小编典典

在Java中(通过JMX)它将是:

import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean;

JMXServiceURL serviceURL = new JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");
MBeanServerConnection bco = JMXConnectorFactory.connect(serviceURL, h).getMBeanServerConnection();

DomainRuntimeServiceMBean domainRuntimeServiceMBean = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler.newProxyInstance(bco, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME));        
DomainMBean dem = domainRuntimeServiceMBean.getDomainConfiguration();
JMSSystemResourceMBean[] jmsSRs = dem.getJMSSystemResources();

JMSServerMBean[] jmsSvrs = dem.getJMSServers();
for(JMSServerMBean jmsSvr : jmsSvrs){
  System.out.println("JMS Servername: "+jmsSvr.getName());
}

for(JMSSystemResourceMBean jmsSR : jmsSRs){
  System.err.println(jmsSR.getName());
  QueueBean[] qbeans = jmsSR.getJMSResource().getQueues();
    for(QueueBean qbean : qbeans){
      System.out.println("JNDI NAME: "+qbean.getJNDIName()+" queuename : "+qbean.getName());
    }
}
2020-06-08