我需要打印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());
答案 0 :(得分:2)
在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());
}
}
来自here
的示例答案 1 :(得分:1)
我曾经使用WLST脚本来显示Weblogic域中的所有JMS队列。也许你可以尝试类似的东西:
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()