Search in sources :

Example 16 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class LocalTestServer method listAllSubscribersForTopic.

@Override
public List<String> listAllSubscribersForTopic(final String s) throws Exception {
    ObjectName objectName = ObjectNameBuilder.DEFAULT.getAddressObjectName(new SimpleString(s));
    AddressControl topic = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), objectName, AddressControl.class, false);
    Object[] subInfos = topic.getQueueNames();
    List<String> subs = new ArrayList<>();
    for (Object o : subInfos) {
        subs.add(((String) o).split("\\.")[1]);
    }
    return subs;
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ObjectName(javax.management.ObjectName)

Example 17 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class JMSServerManagerImpl method destroyTopic.

@Override
public synchronized boolean destroyTopic(final String name, final boolean removeConsumers) throws Exception {
    checkInitialised();
    AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.ADDRESS + name);
    if (addressControl != null) {
        for (String queueName : addressControl.getQueueNames()) {
            Binding binding = server.getPostOffice().getBinding(new SimpleString(queueName));
            if (binding == null) {
                ActiveMQJMSServerLogger.LOGGER.noQueueOnTopic(queueName, name);
                continue;
            }
            // We can't remove the remote binding. As this would be the bridge associated with the topic on this case
            if (binding.getType() != BindingType.REMOTE_QUEUE) {
                server.destroyQueue(SimpleString.toSimpleString(queueName), null, !removeConsumers, removeConsumers, true);
            }
        }
        if (addressControl.getQueueNames().length == 0) {
            try {
                server.removeAddressInfo(SimpleString.toSimpleString(name), null);
            } catch (ActiveMQAddressDoesNotExistException e) {
            // ignore
            }
            removeFromBindings(topics, topicBindings, name);
            topics.remove(name);
            topicBindings.remove(name);
            storage.deleteDestination(PersistedType.Topic, name);
            sendNotification(JMSNotificationType.TOPIC_DESTROYED, name);
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Binding(org.apache.activemq.artemis.core.postoffice.Binding) ActiveMQAddressDoesNotExistException(org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 18 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class AddressControlTest method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createAddress(address, RoutingType.ANYCAST, false);
    AddressControl addressControl = createManagementControl(address);
    Assert.assertEquals(0, addressControl.getQueueNames().length);
    session.createQueue(address, RoutingType.ANYCAST, address);
    Assert.assertEquals(1, addressControl.getQueueNames().length);
    addressControl.sendMessage(null, Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, null, null);
    Wait.waitFor(() -> addressControl.getMessageCount() == 1);
    Assert.assertEquals(1, addressControl.getMessageCount());
    ClientConsumer consumer = session.createConsumer(address);
    ClientMessage message = consumer.receive(500);
    assertNotNull(message);
    byte[] buffer = new byte[message.getBodyBuffer().readableBytes()];
    message.getBodyBuffer().readBytes(buffer);
    assertEquals("test", new String(buffer));
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RandomUtil.randomString(org.apache.activemq.artemis.tests.util.RandomUtil.randomString) JsonString(javax.json.JsonString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 19 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class AddressControlTest method testGetRoutingTypesAsJSON.

@Test
public void testGetRoutingTypesAsJSON() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createAddress(address, RoutingType.ANYCAST, false);
    AddressControl addressControl = createManagementControl(address);
    JsonArray jsonArray = JsonUtil.readJsonArray(addressControl.getRoutingTypesAsJSON());
    assertEquals(1, jsonArray.size());
    assertEquals(RoutingType.ANYCAST.toString(), ((JsonString) jsonArray.get(0)).getString());
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) JsonArray(javax.json.JsonArray) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 20 with AddressControl

use of org.apache.activemq.artemis.api.core.management.AddressControl in project activemq-artemis by apache.

the class AddressControlTest method testGetMessageCount.

@Test
public void testGetMessageCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    session.createAddress(address, RoutingType.ANYCAST, false);
    AddressControl addressControl = createManagementControl(address);
    assertEquals(0, addressControl.getMessageCount());
    ClientProducer producer = session.createProducer(address.toString());
    producer.send(session.createMessage(false));
    assertEquals(0, addressControl.getMessageCount());
    session.createQueue(address, RoutingType.ANYCAST, address);
    producer.send(session.createMessage(false));
    assertTrue(Wait.waitFor(() -> addressControl.getMessageCount() == 1, 2000, 100));
    session.createQueue(address, RoutingType.ANYCAST, address.concat('2'));
    producer.send(session.createMessage(false));
    assertTrue(Wait.waitFor(() -> addressControl.getMessageCount() == 2, 2000, 100));
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

AddressControl (org.apache.activemq.artemis.api.core.management.AddressControl)29 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Test (org.junit.Test)18 HashSet (java.util.HashSet)5 Connection (javax.jms.Connection)5 Session (javax.jms.Session)5 JsonString (javax.json.JsonString)5 RandomUtil.randomString (org.apache.activemq.artemis.tests.util.RandomUtil.randomString)5 OperationFailedException (org.jboss.as.controller.OperationFailedException)5 ManagementService (org.apache.activemq.artemis.core.server.management.ManagementService)4 PathAddress (org.jboss.as.controller.PathAddress)4 TextMessage (javax.jms.TextMessage)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 ModelNode (org.jboss.dmr.ModelNode)3 ServiceName (org.jboss.msc.service.ServiceName)3 BytesMessage (javax.jms.BytesMessage)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 ObjectMessage (javax.jms.ObjectMessage)2