简体   繁体   English

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

[英]How to get the list of jms queues from Summary of Resources table of jms module in weblogic?

I need to print the list of jms queues of the jms module. 我需要打印jms模块的jms队列列表。 I use this code to look up the needed queue and get parameters but how to get the names of all queues and print them? 我使用此代码查找所需的队列并获取参数,但是如何获取所有队列的名称并打印它们呢?

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());

In Java (via JMX) it would be: 在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());
    }
}

Example from here 这里的例子

I once used WLST scripts to display all JMS Queues within a Weblogic Domain. 我曾经使用WLST脚本显示Weblogic域中的所有JMS队列。 Probably you can try something like: 可能您可以尝试类似的方法:

connect('AdminUser', 'AdminPW', 't3://AdminURL')
easeSyntax()

allJMSResources = cmo.getJMSSystemResources()
for jmsResource in allJMSResources:
    module = jmsResource.getName()
    print "MODULE", module
    QList = jmsResource.getJMSResource().getUniformDistributedQueues()
    for queue in QList:
        print "QUEUE", queue.getName(), " JNDINAME", queue.getJNDIName()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM