Search in sources :

Example 1 with QueueControl

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();
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 2 with QueueControl

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());
}
Also used : Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with QueueControl

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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Session(javax.jms.Session)

Example 4 with QueueControl

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();
        }
    }
}
Also used : Connection(javax.jms.Connection) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Session(javax.jms.Session) TemporaryTopic(javax.jms.TemporaryTopic) Test(org.junit.Test)

Example 5 with QueueControl

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());
}
Also used : ManagementServiceImpl(org.apache.activemq.artemis.core.server.management.impl.ManagementServiceImpl) AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) FakeStorageManager(org.apache.activemq.artemis.tests.integration.server.FakeStorageManager) Configuration(org.apache.activemq.artemis.core.config.Configuration) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Aggregations

QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)109 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)87 Test (org.junit.Test)79 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)50 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)33 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)24 HashMap (java.util.HashMap)21 Map (java.util.Map)18 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)9 ArrayList (java.util.ArrayList)7 JsonObject (javax.json.JsonObject)7 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)7 MessageProducer (javax.jms.MessageProducer)6 TextMessage (javax.jms.TextMessage)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Session (javax.jms.Session)5 JsonArray (javax.json.JsonArray)5 Queue (org.apache.activemq.artemis.core.server.Queue)5