use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method getQueueNames.
@Override
public String[] getQueueNames(String routingType) {
checkStarted();
clearIO();
try {
Object[] queueControls = server.getManagementService().getResources(QueueControl.class);
List<String> names = new ArrayList<>();
for (int i = 0; i < queueControls.length; i++) {
QueueControl queueControl = (QueueControl) queueControls[i];
if (routingType != null && queueControl.getRoutingType().equals(routingType.toUpperCase())) {
names.add(queueControl.getName());
} else if (routingType == null) {
names.add(queueControl.getName());
}
}
String[] result = new String[names.size()];
return names.toArray(result);
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class JMSMessageCounterTest method testMessageCounter.
@Test
public void testMessageCounter() throws Exception {
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = createQueue(true, "Test");
MessageProducer producer = sess.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
TextMessage mess = sess.createTextMessage("msg" + i);
producer.send(mess);
}
conn.close();
QueueControl control = (QueueControl) server.getManagementService().getResource(ResourceNames.QUEUE + queue.getQueueName());
assertNotNull(control);
System.out.println(control.listMessageCounterAsHTML());
jmsServer.stop();
restartServer();
control = (QueueControl) server.getManagementService().getResource(ResourceNames.QUEUE + queue.getQueueName());
assertNotNull(control);
System.out.println(control.listMessageCounterAsHTML());
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class JMSConsumerTest method testAckOfExpired.
public void testAckOfExpired() throws Exception {
ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=4&jms.sendAcksAsync=false");
connection = fact.createActiveMQConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = (ActiveMQDestination) (destinationType == ActiveMQDestination.QUEUE_TYPE ? session.createQueue("test") : session.createTopic("test"));
MessageConsumer consumer = session.createConsumer(destination);
connection.setStatsEnabled(true);
Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sendSession.createProducer(destination);
producer.setTimeToLive(1000);
final int count = 4;
for (int i = 0; i < count; i++) {
TextMessage message = sendSession.createTextMessage("" + i);
producer.send(message);
}
// let first bunch in queue expire
Thread.sleep(2000);
producer.setTimeToLive(0);
for (int i = 0; i < count; i++) {
TextMessage message = sendSession.createTextMessage("no expiry" + i);
producer.send(message);
}
ActiveMQMessageConsumer amqConsumer = (ActiveMQMessageConsumer) consumer;
for (int i = 0; i < count; i++) {
TextMessage msg = (TextMessage) amqConsumer.receive();
assertNotNull(msg);
assertTrue("message has \"no expiry\" text: " + msg.getText(), msg.getText().contains("no expiry"));
// force an ack when there are expired messages
amqConsumer.acknowledge();
}
assertEquals("consumer has expiredMessages", count, amqConsumer.getConsumerStats().getExpiredMessageCount().getCount());
QueueControl view = createQueueControl(destination.getPhysicalName());
assertEquals("Wrong inFlightCount: " + view.getDeliveringCount(), 0, view.getDeliveringCount());
assertEquals("Wrong dispatch count: " + view.getMessagesAdded(), 8, view.getMessagesAdded());
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class AdvisoryOpenWireTest method testTempTopicLeak.
@Test
public void testTempTopicLeak() throws Exception {
Connection connection = null;
try {
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic temporaryTopic = session.createTemporaryTopic();
temporaryTopic.delete();
Object[] queueResources = server.getManagementService().getResources(QueueControl.class);
for (Object queueResource : queueResources) {
if (((QueueControl) queueResource).getAddress().equals("ActiveMQ.Advisory.TempTopic")) {
QueueControl queueControl = (QueueControl) queueResource;
Wait.waitFor(() -> queueControl.getMessageCount() == 0);
assertNotNull("addressControl for temp advisory", queueControl);
Wait.assertEquals(0, queueControl::getMessageCount);
Wait.assertEquals(2, queueControl::getMessagesAdded);
}
}
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ManagementServiceImplTest method testGetResources.
@Test
public void testGetResources() throws Exception {
Configuration config = createBasicConfig().setJMXManagementEnabled(false);
ManagementServiceImpl managementService = new ManagementServiceImpl(null, config);
managementService.setStorageManager(new NullStorageManager());
SimpleString address = RandomUtil.randomSimpleString();
managementService.registerAddress(new AddressInfo(address));
Queue queue = new FakeQueue(RandomUtil.randomSimpleString());
managementService.registerQueue(queue, RandomUtil.randomSimpleString(), new FakeStorageManager());
Object[] addresses = managementService.getResources(AddressControl.class);
Assert.assertEquals(1, addresses.length);
Assert.assertTrue(addresses[0] instanceof AddressControl);
AddressControl addressControl = (AddressControl) addresses[0];
Assert.assertEquals(address.toString(), addressControl.getAddress());
Object[] queues = managementService.getResources(QueueControl.class);
Assert.assertEquals(1, queues.length);
Assert.assertTrue(queues[0] instanceof QueueControl);
QueueControl queueControl = (QueueControl) queues[0];
Assert.assertEquals(queue.getName().toString(), queueControl.getName());
}
Aggregations