gpt4 book ai didi

java - 如何从weblogic中jms模块的资源汇总表中获取jms队列列表?

转载 作者:行者123 更新时间:2023-11-30 08:21:40 25 4
gpt4 key购买 nike

我需要打印 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());

最佳答案

在 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

关于java - 如何从weblogic中jms模块的资源汇总表中获取jms队列列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25030022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com