我有以下配置:
@Configuration
public class ConfigureRMI {
@Value("${jmx.rmi.host:localhost}")
private String rmiHost;
@Value("${jmx.rmi.port:1099}")
private Integer rmiPort;
@Bean
public RmiRegistryFactoryBean rmiRegistry() {
final RmiRegistryFactoryBean rmiRegistryFactoryBean = new RmiRegistryFactoryBean();
rmiRegistryFactoryBean.setPort(rmiPort);
rmiRegistryFactoryBean.setAlwaysCreate(true);
return rmiRegistryFactoryBean;
}
@Bean
@DependsOn("rmiRegistry")
public ConnectorServerFactoryBean connectorServerFactoryBean() throws Exception {
final ConnectorServerFactoryBean connectorServerFactoryBean = new ConnectorServerFactoryBean();
connectorServerFactoryBean.setObjectName("connector:name=rmi");
connectorServerFactoryBean.setServiceUrl(String.format("service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", rmiHost, rmiPort, rmiHost, rmiPort));
return connectorServerFactoryBean;
}
@Bean
@DependsOn("connectorServerFactoryBean")
public DestinationViewMBean queueMonitor() {
JMXConnectorServer connector = null;
MBeanServerConnection connection;
ObjectName nameConsumers;
try {
connector = connectorServerFactoryBean().getObject();
connection = connector.getMBeanServer();
nameConsumers = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=tasks");
} catch (Exception e) {
e.printStackTrace();
return null;
}
DestinationViewMBean mbView = MBeanServerInvocationHandler.newProxyInstance(connection, nameConsumers, DestinationViewMBean.class, true);
return mbView;
}
}
它配置并实例化DestinationViewMBean,我稍后将在以下代码中尝试使用它:
Long queueSize = queueMonitor.getQueueSize();
但是它引发异常javax.management.InstanceNotFoundException: org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=tasks
我确定名称与输入的名称相同。我可以在ActiveMQ Web控制台中看到brocker名称和tasks
队列,元素按预期进行排队和出队。但是我无法监视队列大小。我使用的方法(我提供的方法)来自SO的许多答案以及JMX和ActiveMQ的手册页。
我想知道我是否缺少明显的东西。我关闭了防火墙,我在本地主机上。为什么DestinationViewMBean无法找到队列?
UPD:我使用JConsole来检查MBean名称。我设法修复InstanceNotFoundException,但是现在我无法从Bean中获取任何属性。我在调试器中尝试了很多(仅在DestinationViewMBean
接口中可以找到的属性中运行)。但是,每次尝试使用属性获取器时,我都会得到javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for QueueSize
(或其他任何属性)。