Search in sources :

Example 1 with BrokerViewMBean

use of org.apache.activemq.broker.jmx.BrokerViewMBean in project activemq-artemis by apache.

the class ManagementContextXBeanConfigTest method assertAuthentication.

public void assertAuthentication(JMXConnector connector) throws Exception {
    connector.connect();
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    ObjectName name = new ObjectName("test.domain:type=Broker,brokerName=localhost");
    BrokerViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
    LOG.info("Broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName());
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 2 with BrokerViewMBean

use of org.apache.activemq.broker.jmx.BrokerViewMBean in project activemq-artemis by apache.

the class AdvisoryJmxTest method testCreateDeleteDestinations.

public void testCreateDeleteDestinations() throws Exception {
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
    JMXConnector connector = JMXConnectorFactory.connect(url, null);
    connector.connect();
    MBeanServerConnection connection = connector.getMBeanServerConnection();
    ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
    BrokerViewMBean brokerMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
    Connection conn = createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = sess.createConsumer(sess.createTopic("ActiveMQ.Advisory.Queue"));
    conn.start();
    Destination dest = sess.createQueue("test");
    brokerMbean.addQueue("test");
    ActiveMQMessage msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
    brokerMbean.removeQueue("test");
    msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 1);
    brokerMbean.addQueue("test");
    msg = (ActiveMQMessage) consumer.receive(1000);
    assertNotNull(msg);
    assertTrue(msg.getDataStructure() instanceof DestinationInfo);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
    assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) DestinationInfo(org.apache.activemq.command.DestinationInfo) JMXConnector(javax.management.remote.JMXConnector) Connection(javax.jms.Connection) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Session(javax.jms.Session) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Example 3 with BrokerViewMBean

use of org.apache.activemq.broker.jmx.BrokerViewMBean in project activemq-artemis by apache.

the class MQTTNetworkOfBrokersFailoverTest method assertOneDurableSubOn.

@SuppressWarnings("unused")
private void assertOneDurableSubOn(BrokerService broker, String subName) throws Exception {
    BrokerViewMBean brokerView = broker.getAdminView();
    ObjectName[] activeDurableSubs = brokerView.getDurableTopicSubscribers();
    ObjectName[] inactiveDurableSubs = brokerView.getInactiveDurableTopicSubscribers();
    ObjectName[] allDurables = (ObjectName[]) ArrayUtils.addAll(activeDurableSubs, inactiveDurableSubs);
    assertEquals(1, allDurables.length);
    // at this point our assertions should prove that we have only on durable sub
    DurableSubscriptionViewMBean durableSubView = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(allDurables[0], DurableSubscriptionViewMBean.class, true);
    assertEquals(subName, durableSubView.getClientId());
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) DurableSubscriptionViewMBean(org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean) ObjectName(javax.management.ObjectName)

Example 4 with BrokerViewMBean

use of org.apache.activemq.broker.jmx.BrokerViewMBean in project activemq-artemis by apache.

the class MQTTNetworkOfBrokersFailoverTest method assertQueueExistsOn.

private void assertQueueExistsOn(BrokerService broker, String queueName) throws Exception {
    BrokerViewMBean brokerView = broker.getAdminView();
    ObjectName[] queueNames = brokerView.getQueues();
    assertEquals(1, queueNames.length);
    assertTrue(queueNames[0].toString().contains(queueName));
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) ObjectName(javax.management.ObjectName)

Example 5 with BrokerViewMBean

use of org.apache.activemq.broker.jmx.BrokerViewMBean in project activemq-artemis by apache.

the class JmxCreateNCTest method testBridgeRegistration.

@Test
public void testBridgeRegistration() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName(BROKER_NAME);
    // explicitly set this so no funny issues
    broker.setUseJmx(true);
    broker.start();
    broker.waitUntilStarted();
    // now create network connector over JMX
    ObjectName brokerObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME);
    BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext().newProxyInstance(brokerObjectName, BrokerViewMBean.class, true);
    assertNotNull("We could not retrieve the broker from JMX", proxy);
    // let's add the NC
    String connectoName = proxy.addNetworkConnector("static:(tcp://localhost:61617)");
    assertEquals("NC", connectoName);
    // Make sure we can retrieve the NC through JMX
    ObjectName networkConnectorObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME + ",connector=networkConnectors,networkConnectorName=" + connectoName);
    NetworkConnectorViewMBean nc = (NetworkConnectorViewMBean) broker.getManagementContext().newProxyInstance(networkConnectorObjectName, NetworkConnectorViewMBean.class, true);
    assertNotNull(nc);
    assertEquals("NC", nc.getName());
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) NetworkConnectorViewMBean(org.apache.activemq.broker.jmx.NetworkConnectorViewMBean) BrokerService(org.apache.activemq.broker.BrokerService) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ObjectName (javax.management.ObjectName)9 BrokerViewMBean (org.apache.activemq.broker.jmx.BrokerViewMBean)9 MBeanServerConnection (javax.management.MBeanServerConnection)3 Test (org.junit.Test)3 Container (io.fabric8.api.Container)2 FabricService (io.fabric8.api.FabricService)2 Profile (io.fabric8.api.Profile)2 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)2 LinkedList (java.util.LinkedList)2 IOException (java.io.IOException)1 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 JMXConnector (javax.management.remote.JMXConnector)1 JMXServiceURL (javax.management.remote.JMXServiceURL)1 BrokerService (org.apache.activemq.broker.BrokerService)1 DurableSubscriptionViewMBean (org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean)1 NetworkConnectorViewMBean (org.apache.activemq.broker.jmx.NetworkConnectorViewMBean)1