Search in sources :

Example 36 with QueueControl

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

the class QueueControlTest method testMoveMessageToUnknownQueue.

@Test
public void testMoveMessageToUnknownQueue() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString unknownQueue = 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));
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 1, 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");
    // moved all messages to unknown queue
    try {
        queueControl.moveMessage(messageID, unknownQueue.toString());
        Assert.fail("operation must fail if the other queue does not exist");
    } catch (Exception e) {
    }
    Assert.assertEquals(1, getMessageCount(queueControl));
    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) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Test(org.junit.Test)

Example 37 with QueueControl

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

the class QueueControlTest method testChangeMessagePriority.

@Test
public void testChangeMessagePriority() throws Exception {
    byte originalPriority = (byte) 1;
    byte newPriority = (byte) 8;
    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);
    message.setPriority(originalPriority);
    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");
    boolean priorityChanged = queueControl.changeMessagePriority(messageID, newPriority);
    Assert.assertTrue(priorityChanged);
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage m = consumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(newPriority, 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) Test(org.junit.Test)

Example 38 with QueueControl

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

the class QueueControlTest method testMoveMessagesBack.

@Test
public void testMoveMessagesBack() throws Exception {
    server.createQueue(new SimpleString("q1"), RoutingType.MULTICAST, new SimpleString("q1"), null, durable, false);
    server.createQueue(new SimpleString("q2"), RoutingType.MULTICAST, new SimpleString("q2"), null, durable, false);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(true, true);
    ClientProducer prod1 = session.createProducer("q1");
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = session.createMessage(durable);
        msg.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, new SimpleString("dupl-" + i));
        prod1.send(msg);
    }
    session.commit();
    ClientConsumer consumer = session.createConsumer("q1", true);
    session.start();
    assertNotNull(consumer.receive(5000));
    consumer.close();
    QueueControl q1Control = ManagementControlHelper.createQueueControl(new SimpleString("q1"), new SimpleString("q1"), mbeanServer);
    QueueControl q2Control = ManagementControlHelper.createQueueControl(new SimpleString("q2"), new SimpleString("q2"), mbeanServer);
    assertEquals(10, q1Control.moveMessages(null, "q2"));
    consumer = session.createConsumer("q2", true);
    assertNotNull(consumer.receive(500));
    consumer.close();
    q2Control.moveMessages(null, "q1", false);
    session.start();
    consumer = session.createConsumer("q1");
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    consumer.close();
    session.deleteQueue("q1");
    session.deleteQueue("q2");
    session.close();
    locator.close();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 39 with QueueControl

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

the class QueueControlTest method testGetFirstMessage.

@Test
public void testGetFirstMessage() 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, getMessageCount(queueControl));
    // It's empty, so it's supposed to be like this
    assertEquals("[{}]", queueControl.getFirstMessageAsJSON());
    long beforeSend = System.currentTimeMillis();
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(false).putStringProperty("x", "valueX").putStringProperty("y", "valueY"));
    System.out.println("first:" + queueControl.getFirstMessageAsJSON());
    long firstMessageTimestamp = queueControl.getFirstMessageTimestamp();
    System.out.println("first message timestamp: " + firstMessageTimestamp);
    assertTrue(beforeSend <= firstMessageTimestamp);
    assertTrue(firstMessageTimestamp <= System.currentTimeMillis());
    long firstMessageAge = queueControl.getFirstMessageAge();
    System.out.println("first message age: " + firstMessageAge);
    assertTrue(firstMessageAge <= (System.currentTimeMillis() - firstMessageTimestamp));
    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)

Example 40 with QueueControl

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

the class QueueControlTest method testMoveMessage.

@Test
public void testMoveMessage() throws Exception {
    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 2 messages on queue
    producer.send(session.createMessage(durable));
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    QueueControl otherQueueControl = createManagementControl(otherAddress, otherQueue);
    assertMessageMetrics(queueControl, 2, durable);
    assertMessageMetrics(otherQueueControl, 0, 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");
    boolean moved = queueControl.moveMessage(messageID, otherQueue.toString());
    Assert.assertTrue(moved);
    assertMessageMetrics(queueControl, 1, durable);
    assertMessageMetrics(otherQueueControl, 1, durable);
    consumeMessages(1, session, queue);
    consumeMessages(1, session, otherQueue);
    session.deleteQueue(queue);
    session.deleteQueue(otherQueue);
}
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)

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