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

橙三吉。 提交于 2019-12-02 01:50:59

问题


I need to print the list of jms queues of the jms module. 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());

回答1:


In Java (via JMX) it would be:

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




回答2:


I once used WLST scripts to display all JMS Queues within a Weblogic Domain. 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()


来源:https://stackoverflow.com/questions/25030022/how-to-get-the-list-of-jms-queues-from-summary-of-resources-table-of-jms-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!