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;
}
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;
}
}
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));
}
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());
}
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));
}
Aggregations