Search in sources :

Example 31 with QueueControl

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

the class QueueControlTest method testResetMessagesKilled.

@Test
public void testResetMessagesKilled() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getMessagesExpired());
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(durable);
    producer.send(message);
    // the message IDs are set on the server
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(1, messages.length);
    long messageID = (Long) messages[0].get("messageID");
    queueControl.sendMessageToDeadLetterAddress(messageID);
    Assert.assertEquals(1, queueControl.getMessagesKilled());
    assertMessageMetrics(queueControl, 0, durable);
    message = session.createMessage(false);
    producer.send(message);
    // send to DLA the old-fashioned way
    ClientConsumer consumer = session.createConsumer(queue);
    for (int i = 0; i < server.getAddressSettingsRepository().getMatch(queue.toString()).getMaxDeliveryAttempts(); i++) {
        message = consumer.receive(500);
        assertNotNull(message);
        message.acknowledge();
        session.rollback();
    }
    consumer.close();
    Assert.assertEquals(2, queueControl.getMessagesKilled());
    queueControl.resetMessagesKilled();
    Assert.assertEquals(0, queueControl.getMessagesKilled());
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Map(java.util.Map) HashMap(java.util.HashMap) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 32 with QueueControl

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

the class QueueControlTest method testGetConsumerCount.

@Test
public void testGetConsumerCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getConsumerCount());
    ClientConsumer consumer = session.createConsumer(queue);
    Assert.assertEquals(1, queueControl.getConsumerCount());
    consumer.close();
    Assert.assertEquals(0, queueControl.getConsumerCount());
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 33 with QueueControl

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

the class QueueControlTest method testListMessageCounter.

@Test
public void testListMessageCounter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
    serverControl.enableMessageCounters();
    serverControl.setMessageCounterSamplePeriod(100);
    String jsonString = queueControl.listMessageCounter();
    MessageCounterInfo info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(0, info.getDepth());
    Assert.assertEquals(0, info.getCount());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    Thread.sleep(200);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(1, info.getDepth());
    Assert.assertEquals(1, info.getDepthDelta());
    Assert.assertEquals(1, info.getCount());
    Assert.assertEquals(1, info.getCountDelta());
    producer.send(session.createMessage(durable));
    Thread.sleep(200);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(2, info.getDepth());
    Assert.assertEquals(1, info.getDepthDelta());
    Assert.assertEquals(2, info.getCount());
    Assert.assertEquals(1, info.getCountDelta());
    consumeMessages(2, session, queue);
    Thread.sleep(200);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(0, info.getDepth());
    Assert.assertEquals(-2, info.getDepthDelta());
    Assert.assertEquals(2, info.getCount());
    Assert.assertEquals(0, info.getCountDelta());
    session.deleteQueue(queue);
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) MessageCounterInfo(org.apache.activemq.artemis.api.core.management.MessageCounterInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 34 with QueueControl

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

the class QueueControlTest method testMoveMessages2.

@Test
public void testMoveMessages2() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queueA = new SimpleString("A");
    SimpleString queueB = new SimpleString("B");
    SimpleString queueC = new SimpleString("C");
    server.createQueue(address, RoutingType.MULTICAST, queueA, null, durable, false);
    server.createQueue(address, RoutingType.MULTICAST, queueB, null, durable, false);
    server.createQueue(address, RoutingType.MULTICAST, queueC, null, durable, false);
    QueueControl queueControlA = createManagementControl(address, queueA);
    QueueControl queueControlB = createManagementControl(address, queueB);
    QueueControl queueControlC = createManagementControl(address, queueC);
    // send two messages on queueA
    queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody".getBytes()), true, "myUser", "myPassword");
    queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody2".getBytes()), true, "myUser", "myPassword");
    Wait.assertEquals(2, () -> getMessageCount(queueControlA));
    Wait.assertEquals(0, () -> getMessageCount(queueControlB));
    Wait.assertEquals(0, () -> getMessageCount(queueControlC));
    // move 2 messages from queueA to queueB
    queueControlA.moveMessages(null, queueB.toString());
    Thread.sleep(500);
    Wait.assertEquals(0, () -> getMessageCount(queueControlA));
    Wait.assertEquals(2, () -> getMessageCount(queueControlB));
    // move 1 message to queueC
    queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody3".getBytes()), true, "myUser", "myPassword");
    Wait.assertEquals(1, () -> getMessageCount(queueControlA));
    queueControlA.moveMessages(null, queueC.toString());
    Wait.assertEquals(1, () -> getMessageCount(queueControlC));
    Wait.assertEquals(0, () -> getMessageCount(queueControlA));
    // move all messages back to A
    queueControlB.moveMessages(null, queueA.toString());
    Wait.assertEquals(2, () -> getMessageCount(queueControlA));
    Wait.assertEquals(0, () -> getMessageCount(queueControlB));
    queueControlC.moveMessages(null, queueA.toString());
    Wait.assertEquals(3, () -> getMessageCount(queueControlA));
    Wait.assertEquals(0, () -> getMessageCount(queueControlC));
    // consume the message from queueA
    ClientConsumer consumer = session.createConsumer(queueA);
    ClientMessage m1 = consumer.receive(500);
    ClientMessage m2 = consumer.receive(500);
    ClientMessage m3 = consumer.receive(500);
    m1.acknowledge();
    m2.acknowledge();
    m3.acknowledge();
    consumer.close();
    session.deleteQueue(queueA);
    session.deleteQueue(queueB);
    session.deleteQueue(queueC);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 35 with QueueControl

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

the class QueueControlTest method testGetMessagesAcknowledged.

@Test
public void testGetMessagesAcknowledged() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, false);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(1, queueControl.getMessagesAcknowledged());
    producer.send(session.createMessage(false));
    consumeMessages(1, session, queue);
    Assert.assertEquals(2, queueControl.getMessagesAcknowledged());
    // ManagementTestBase.consumeMessages(2, session, queue);
    // Assert.assertEquals(2, getMessagesAdded(queueControl));
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) 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