Search in sources :

Example 21 with QueueControl

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

the class QueueControlTest method testListScheduledMessages.

@Test
public void testListScheduledMessages() throws Exception {
    long delay = 2000;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    int intValue = RandomUtil.randomInt();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(durable);
    message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + delay);
    message.putIntProperty(new SimpleString("key"), intValue);
    producer.send(message);
    // unscheduled message
    producer.send(session.createMessage(durable));
    Map<String, Object>[] messages = queueControl.listScheduledMessages();
    Assert.assertEquals(1, messages.length);
    assertScheduledMetrics(queueControl, 1, durable);
    Assert.assertEquals(intValue, Integer.parseInt((messages[0].get("key")).toString()));
    Thread.sleep(delay + 500);
    messages = queueControl.listScheduledMessages();
    Assert.assertEquals(0, messages.length);
    consumeMessages(2, session, queue);
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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 22 with QueueControl

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

the class QueueControlTest method testRemoveMessage.

@Test
public void testRemoveMessage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send 2 messages on queue
    producer.send(session.createMessage(durable));
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 2, durable);
    // the message IDs are set on the server
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(2, messages.length);
    long messageID = (Long) messages[0].get("messageID");
    // delete 1st message
    boolean deleted = queueControl.removeMessage(messageID);
    Assert.assertTrue(deleted);
    assertMessageMetrics(queueControl, 1, durable);
    // check there is a single message to consume from queue
    consumeMessages(1, session, queue);
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 23 with QueueControl

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

the class QueueControlTest method testListMessagesAsJSONWithFilter.

@Test
public void testListMessagesAsJSONWithFilter() throws Exception {
    SimpleString key = new SimpleString("key");
    long matchingValue = RandomUtil.randomLong();
    long unmatchingValue = matchingValue + 1;
    String filter = key + " =" + matchingValue;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    ClientMessage matchingMessage = session.createMessage(durable);
    matchingMessage.putLongProperty(key, matchingValue);
    producer.send(matchingMessage);
    ClientMessage unmatchingMessage = session.createMessage(durable);
    unmatchingMessage.putLongProperty(key, unmatchingValue);
    producer.send(unmatchingMessage);
    String jsonString = queueControl.listMessagesAsJSON(filter);
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(1, array.size());
    long l = Long.parseLong(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
    Assert.assertEquals(matchingValue, l);
    consumeMessages(2, session, queue);
    jsonString = queueControl.listMessagesAsJSON(filter);
    Assert.assertNotNull(jsonString);
    array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(0, array.size());
    session.deleteQueue(queue);
}
Also used : JsonArray(javax.json.JsonArray) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 24 with QueueControl

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

the class QueueControlTest method testChangeMessagePriorityWithInvalidValue.

@Test
public void testChangeMessagePriorityWithInvalidValue() throws Exception {
    byte invalidPriority = (byte) 23;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(durable);
    producer.send(message);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(1, getMessageCount(queueControl));
    // 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");
    try {
        queueControl.changeMessagePriority(messageID, invalidPriority);
        Assert.fail("operation fails when priority value is < 0 or > 9");
    } catch (Exception e) {
    }
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage m = consumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertTrue(invalidPriority != m.getPriority());
    consumer.close();
    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) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 25 with QueueControl

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

the class QueueControlTest method testResetMessagesAdded.

@Test
public void testResetMessagesAdded() 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, getMessagesAdded(queueControl));
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    Assert.assertEquals(1, getMessagesAdded(queueControl));
    producer.send(session.createMessage(durable));
    Assert.assertEquals(2, getMessagesAdded(queueControl));
    consumeMessages(2, session, queue);
    Assert.assertEquals(2, getMessagesAdded(queueControl));
    queueControl.resetMessagesAdded();
    Assert.assertEquals(0, 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