Search code examples
activemq-classicbroker

How do I specify the JMX port for an embedded activemq instance?


I am creating an embedded activemq instance in order to test creating/deleting topics via JMX. The code looks a bit like the following. broker.connectorPort was my attempt to set the JMX port but it does not work.

String connectString="vm://localhost?broker.persistence=false&broker.useJmx=true&broker.connectorPort=2011"

ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();

activeMQConnectionFactory.setBrokerURL(connectString);

ActiveMQConnection activeMQConnection = (ActiveMQConnection) activeMQConnectionFactory.createConnection();
activeMQConnection.start();

When configuring using activemq.xml the following xml works. Im not sure how to translate this to brokerURL.

<managementContext>
        <managementContext connectorPort="2011" createConnector="true"/>
</managementContext>

Solution

  • Solved by creating broker manually..

        BrokerService broker = new BrokerService();
        broker.setUseJmx(true);
        broker.getManagementContext().setConnectorPort(9999);
        broker.start();