1

I have the following configuration:

@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;
    }
}

It configures and instantiates DestinationViewMBean that I try to use later in code like this:

Long queueSize = queueMonitor.getQueueSize();

But it throws an exception javax.management.InstanceNotFoundException: org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=tasks I'm sure the names are as I typed. I can see the brocker name and tasks queue in ActiveMQ web console, elements are queued and dequeued as intended. But I cant't monitor the queue size. The method I used (the one I provided) was made from many answers here on SO and man pages on JMX and ActiveMQ.

I'm wondering if I'm missing something obvious. I turned firewall down, I'm on localhost. Why can't DestinationViewMBean find the queue?

UPD: I used JConsole to check the MBean name. I managed to fix InstanceNotFoundException but now I can't get any attribute from the bean. I've tried a lot of them in debugger (just run throught the attributes I could find in DestinationViewMBean interface). But on every try of attribute getter I get javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for QueueSize (or any other attribute).

ba3a
  • 330
  • 1
  • 6
  • 17
  • 1
    As a debugging exercise I would recommend you use JConsole to connect to your ActiveMQ instance and then find the MBean you're looking for to ensure the name is *exactly* the same. – Justin Bertram Dec 21 '18 at 16:30
  • Thanks for the way to debug. I've managed to get the needed name for mbean (it happened to be ```"org.apache.camel:context=camel-1,type=endpoints,name=\"activemq://queue:tasks\""```, but now I get ```AttributeNotFoundException``` – ba3a Dec 24 '18 at 12:28
  • That looks like an MBean from Camel rather than ActiveMQ which probably has completely different attributes. – Justin Bertram Dec 25 '18 at 01:31
  • Yeah, but in JConsole it has all the needed attributes. – ba3a Dec 25 '18 at 10:16

0 Answers0