简体   繁体   English

在Wildfly上获取JMS队列ObjectName

[英]Get JMS Queue ObjectName on Wildfly

I want to get number of objects in Queue. 我想获取队列中的对象数。 This is the code I found: 这是我发现的代码:

MBeanServerConnection mbeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName queueName = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queue.getQueueName());
Integer messageCount = (Integer) mbeanServer.getAttribute(queueName, "MessageCount");

There's some problem with this code. 此代码存在一些问题。 First of all there's no ObjectNameBuilder class on wildfly (Is there any module required!?). 首先,wildfly上没有ObjectNameBuilder类(是否需要任何模块!?)。

After using HornetQ ObjectNameBuilder class source code, I've implemented the function by myself, but now getting this error: 使用HornetQ ObjectNameBuilder类源代码后,我已经实现了该功能,但是现在出现此错误:

org.hornetq:module=JMS,type=Queue,name="MyQueueName"

I'm using Wildfly v9.0.1-Final . 我正在使用Wildfly v9.0.1-Final Any suggestion? 有什么建议吗?

I was facing a similar problem and some details made all the difference. 我面临着类似的问题,一些细节使一切变得不同。

If you are running Wildfly in domain mode so you must connect as follows: 如果您在域模式下运行Wildfly,则必须按以下方式进行连接:

HashMap environment = new HashMap();
environment.put(JMXConnector.CREDENTIALS, new String[] { "your_user", "your_password" });
JMXServiceURL url = new JMXServiceURL("service:jmx:http-remoting-jmx://your_host:8080");

JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

Attention: Please note that the port for remote connection should be 8080, not 9990. Another important detail: your_user must be a user of the application type and no a mgmt type user. 注意:请注意,用于远程连接的端口应该是8080,而不是9990。另一个重要的细节:your_user必须是应用程序类型的用户,而不是mgmt类型的用户。

Also you should leave the setting on your JMX domain.xml as follows: 另外,您还应该按如下所示将设置保留在JMX domain.xml上:

<subsystem xmlns="urn:jboss:domain:jmx:1.3">
   <expose-resolved-model/>
   <expose-expression-model/>
   <remoting-connector use-management-endpoint="false" />
</subsystem>

If you are running Wildfly in standalone mode must use the 9990 port and authentication is not required. 如果以独立模式运行Wildfly,则必须使用9990端口,并且不需要身份验证。

One more detail, try to recover the information as follows: 再详细一点,请尝试恢复信息,如下所示:

String queueName = "YourQueue"; // use your queue name jms-queue 

String mbeanObjectName = "jboss.as:subsystem=messaging,hornetq-server=default,jms-queue=" + queueName;

ObjectName objectName = ObjectName.getInstance(mbeanObjectName);

JMSQueueControl jmsQueueControl = (JMSQueueControl) MBeanServerInvocationHandler.newProxyInstance(connection, objectName, JMSQueueControl.class, false);

assert jmsQueueControl != null;
long msgCount = jmsQueueControl.countMessages(null);
System.out.println(mbeanObjectName + " message count: " + msgCount);

Note that instead of using the key "org.hornetq:module=JMS,type=Queue,name=" I used "jboss.as:subsystem=messaging,hornetq-server=default,jms-queue=". 请注意,不是使用键“ org.hornetq:module = JMS,type = Queue,name =“,而是使用“ jboss.as:subsystem=messaging,hornetq-server=default,jms-queue=”。

Ideally, use jconsole to verify the exact name of your key. 理想情况下,使用jconsole验证密钥的确切名称。

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

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