Search in sources :

Example 11 with QueueControl

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

the class QueueControlTest method testPauseAndResume.

@Test
public void testPauseAndResume() {
    long counterPeriod = 1000;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    try {
        session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
        QueueControl queueControl = createManagementControl(address, queue);
        ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
        serverControl.enableMessageCounters();
        serverControl.setMessageCounterSamplePeriod(counterPeriod);
        Assert.assertFalse(queueControl.isPaused());
        queueControl.pause();
        Assert.assertTrue(queueControl.isPaused());
        queueControl.resume();
        Assert.assertFalse(queueControl.isPaused());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 12 with QueueControl

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

the class QueueControlTest method testRemoveMessagesWithLimit.

@Test
public void testRemoveMessagesWithLimit() throws Exception {
    SimpleString key = new SimpleString("key");
    long matchingValue = RandomUtil.randomLong();
    long unmatchingValue = matchingValue + 1;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    ClientMessage matchingMessage = session.createMessage(durable);
    matchingMessage.putLongProperty(key, matchingValue);
    producer.send(matchingMessage);
    ClientMessage unmatchingMessage = session.createMessage(durable);
    unmatchingMessage.putLongProperty(key, unmatchingValue);
    producer.send(unmatchingMessage);
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 2, durable);
    // removed matching messages to otherQueue
    int removedMatchedMessagesCount = queueControl.removeMessages(5, key + " =" + matchingValue);
    Assert.assertEquals(1, removedMatchedMessagesCount);
    assertMessageMetrics(queueControl, 1, durable);
    // consume the unmatched message from queue
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage m = consumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(unmatchingValue, m.getObjectProperty(key));
    m.acknowledge();
    // check there is no other message to consume:
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
    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) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 13 with QueueControl

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

the class QueueControlTest method testListMessagesWithFilter.

@Test
public void testListMessagesWithFilter() 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);
    assertMessageMetrics(queueControl, 2, durable);
    Map<String, Object>[] messages = queueControl.listMessages(filter);
    Assert.assertEquals(1, messages.length);
    Assert.assertEquals(matchingValue, Long.parseLong(messages[0].get("key").toString()));
    consumeMessages(2, session, queue);
    messages = queueControl.listMessages(filter);
    Assert.assertEquals(0, messages.length);
    assertMessageMetrics(queueControl, 0, durable);
    session.deleteQueue(queue);
}
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) 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 14 with QueueControl

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

the class QueueControlTest method testExpireMessage.

@Test
public void testExpireMessage() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString expiryAddress = RandomUtil.randomSimpleString();
    SimpleString expiryQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    session.createQueue(expiryAddress, RoutingType.MULTICAST, expiryQueue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    QueueControl expiryQueueControl = createManagementControl(expiryAddress, expiryQueue);
    assertMessageMetrics(queueControl, 1, durable);
    assertMessageMetrics(expiryQueueControl, 0, durable);
    // 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");
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(expiryAddress);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    boolean expired = queueControl.expireMessage(messageID);
    Assert.assertTrue(expired);
    Thread.sleep(200);
    assertMessageMetrics(queueControl, 0, durable);
    assertMessageMetrics(expiryQueueControl, 1, durable);
    consumeMessages(0, session, queue);
    consumeMessages(1, session, expiryQueue);
    session.deleteQueue(queue);
    session.deleteQueue(expiryQueue);
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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 15 with QueueControl

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

the class QueueControlTest method testMoveMessagesWithFilter.

/**
 * <ol>
 * <li>send 2 message to queue</li>
 * <li>move messages from queue to otherQueue using management method <em>with filter</em></li>
 * <li>consume the message which <strong>did not</strong> matches the filter from queue</li>
 * <li>consume the message which <strong>did</strong> matches the filter from otherQueue</li>
 * </ol>
 */
@Test
public void testMoveMessagesWithFilter() throws Exception {
    SimpleString key = new SimpleString("key");
    long matchingValue = RandomUtil.randomLong();
    long unmatchingValue = matchingValue + 1;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString otherAddress = RandomUtil.randomSimpleString();
    SimpleString otherQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    session.createQueue(otherAddress, RoutingType.MULTICAST, otherQueue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    ClientMessage matchingMessage = session.createMessage(durable);
    matchingMessage.putLongProperty(key, matchingValue);
    producer.send(matchingMessage);
    ClientMessage unmatchingMessage = session.createMessage(durable);
    unmatchingMessage.putLongProperty(key, unmatchingValue);
    producer.send(unmatchingMessage);
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 2, durable);
    // moved matching messages to otherQueue
    int movedMatchedMessagesCount = queueControl.moveMessages(key + " =" + matchingValue, otherQueue.toString());
    Assert.assertEquals(1, movedMatchedMessagesCount);
    Assert.assertEquals(1, getMessageCount(queueControl));
    // consume the unmatched message from queue
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage m = consumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(unmatchingValue, m.getObjectProperty(key));
    // consume the matched message from otherQueue
    ClientConsumer otherConsumer = session.createConsumer(otherQueue);
    m = otherConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(matchingValue, m.getObjectProperty(key));
    m.acknowledge();
    consumer.close();
    session.deleteQueue(queue);
    otherConsumer.close();
    session.deleteQueue(otherQueue);
}
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) 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