Search in sources :

Example 96 with QueueControl

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

the class QueueControlTest method testMoveMessagesBack2.

@Test
public void testMoveMessagesBack2() 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");
    int NUMBER_OF_MSGS = 10;
    for (int i = 0; i < NUMBER_OF_MSGS; 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(NUMBER_OF_MSGS, q1Control.moveMessages(null, "q2"));
    long[] messageIDs = new long[NUMBER_OF_MSGS];
    consumer = session.createConsumer("q2", true);
    for (int i = 0; i < NUMBER_OF_MSGS; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        messageIDs[i] = msg.getMessageID();
    }
    assertNull(consumer.receiveImmediate());
    consumer.close();
    for (int i = 0; i < NUMBER_OF_MSGS; i++) {
        q2Control.moveMessage(messageIDs[i], "q1");
    }
    session.start();
    consumer = session.createConsumer("q1");
    for (int i = 0; i < NUMBER_OF_MSGS; i++) {
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    consumer.close();
    session.deleteQueue("q1");
    session.deleteQueue("q2");
    session.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 97 with QueueControl

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

the class ActiveMQServerControlTest method testCreateAndDestroyQueue_2.

@Test
public void testCreateAndDestroyQueue_2() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = "color = 'green'";
    boolean durable = true;
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createAddress(address.toString(), "ANYCAST");
    serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), filter, durable, -1, false, false);
    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertEquals(filter, queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());
    serverControl.destroyQueue(name.toString());
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 98 with QueueControl

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

the class ActiveMQServerControlTest method testCreateAndDestroyQueue_3.

@Test
public void testCreateAndDestroyQueue_3() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    boolean durable = true;
    ActiveMQServerControl serverControl = createManagementControl();
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    serverControl.createAddress(address.toString(), "ANYCAST");
    serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, durable, -1, false, false);
    checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
    QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
    Assert.assertEquals(address.toString(), queueControl.getAddress());
    Assert.assertEquals(name.toString(), queueControl.getName());
    Assert.assertNull(queueControl.getFilter());
    Assert.assertEquals(durable, queueControl.isDurable());
    Assert.assertEquals(false, queueControl.isTemporary());
    serverControl.destroyQueue(name.toString());
    checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
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) Test(org.junit.Test)

Example 99 with QueueControl

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

the class BridgeTestBase method removeAllMessages.

protected void removeAllMessages(final String queueName, final int index) throws Exception {
    ManagementService managementService = server0.getManagementService();
    if (index == 1) {
        managementService = server1.getManagementService();
    }
    QueueControl queueControl = (QueueControl) managementService.getResource("queue." + queueName);
    queueControl.removeMessages(null);
}
Also used : ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 100 with QueueControl

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

the class AdvisoryOpenWireTest method testTempQueueLeak.

@Test
public void testTempQueueLeak() throws Exception {
    Connection connection = null;
    try {
        connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue temporaryQueue = session.createTemporaryQueue();
        temporaryQueue.delete();
        Object[] queueResources = server.getManagementService().getResources(QueueControl.class);
        for (Object queueResource : queueResources) {
            if (((QueueControl) queueResource).getAddress().equals("ActiveMQ.Advisory.TempQueue")) {
                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) TemporaryQueue(javax.jms.TemporaryQueue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Session(javax.jms.Session) 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