Search in sources :

Example 41 with QueueControl

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

the class QueueControlTest method testSetExpiryAddress.

@Test
public void testSetExpiryAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    String expiryAddress = RandomUtil.randomString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    AddressSettings addressSettings = new AddressSettings().setExpiryAddress(new SimpleString(expiryAddress));
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    Assert.assertEquals(expiryAddress, queueControl.getExpiryAddress());
    Queue serverqueue = server.locateQueue(queue);
    assertEquals(expiryAddress, serverqueue.getExpiryAddress().toString());
    session.deleteQueue(queue);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 42 with QueueControl

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

the class QueueControlTest method testResetMessagesAcknowledged.

@Test
public void testResetMessagesAcknowledged() 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.getMessagesAcknowledged());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    consumeMessages(1, session, queue);
    Assert.assertEquals(1, queueControl.getMessagesAcknowledged());
    producer.send(session.createMessage(durable));
    consumeMessages(1, session, queue);
    Assert.assertEquals(2, queueControl.getMessagesAcknowledged());
    queueControl.resetMessagesAcknowledged();
    Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
    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 43 with QueueControl

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

the class QueueControlUsingCoreTest method createManagementControl.

@Override
protected QueueControl createManagementControl(final SimpleString address, final SimpleString queue) throws Exception {
    return new QueueControl() {

        private final CoreMessagingProxy proxy = new CoreMessagingProxy(addServerLocator(createInVMNonHALocator()), ResourceNames.QUEUE + queue);

        @Override
        public void flushExecutor() {
            try {
                proxy.invokeOperation("flushExecutor");
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        @Override
        public boolean changeMessagePriority(final long messageID, final int newPriority) throws Exception {
            return (Boolean) proxy.invokeOperation("changeMessagePriority", messageID, newPriority);
        }

        @Override
        public int changeMessagesPriority(final String filter, final int newPriority) throws Exception {
            return (Integer) proxy.invokeOperation("changeMessagesPriority", filter, newPriority);
        }

        @Override
        public long countMessages(final String filter) throws Exception {
            return (Long) proxy.invokeOperation(Long.class, "countMessages", filter);
        }

        @Override
        public long countMessages() throws Exception {
            return (Long) proxy.invokeOperation(Long.class, "countMessages");
        }

        @Override
        public boolean expireMessage(final long messageID) throws Exception {
            return (Boolean) proxy.invokeOperation("expireMessage", messageID);
        }

        @Override
        public int expireMessages(final String filter) throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "expireMessages", filter);
        }

        @Override
        public String getAddress() {
            return (String) proxy.retrieveAttributeValue("address");
        }

        @Override
        public String getUser() {
            return (String) proxy.retrieveAttributeValue("user");
        }

        @Override
        public int getConsumerCount() {
            return (Integer) proxy.retrieveAttributeValue("consumerCount", Integer.class);
        }

        @Override
        public String getDeadLetterAddress() {
            return (String) proxy.retrieveAttributeValue("deadLetterAddress");
        }

        @Override
        public int getMaxConsumers() {
            return (Integer) proxy.retrieveAttributeValue("maxConsumers");
        }

        @Override
        public boolean isPurgeOnNoConsumers() {
            return (Boolean) proxy.retrieveAttributeValue("purgeOnNoConsumers");
        }

        @Override
        public boolean isExclusive() {
            return (Boolean) proxy.retrieveAttributeValue("exclusive");
        }

        @Override
        public boolean isLastValue() {
            return (Boolean) proxy.retrieveAttributeValue("lastValue");
        }

        @Override
        public int getDeliveringCount() {
            return (Integer) proxy.retrieveAttributeValue("deliveringCount", Integer.class);
        }

        @Override
        public long getDeliveringSize() {
            return (Long) proxy.retrieveAttributeValue("deliveringSize", Long.class);
        }

        @Override
        public int getDurableDeliveringCount() {
            return (Integer) proxy.retrieveAttributeValue("durableDeliveringCount", Integer.class);
        }

        @Override
        public long getDurableDeliveringSize() {
            return (Long) proxy.retrieveAttributeValue("durableDeliveringSize", Long.class);
        }

        @Override
        public String getExpiryAddress() {
            return (String) proxy.retrieveAttributeValue("expiryAddress");
        }

        @Override
        public String getFilter() {
            return (String) proxy.retrieveAttributeValue("filter");
        }

        @Override
        public long getMessageCount() {
            return (Long) proxy.retrieveAttributeValue("messageCount", Long.class);
        }

        @Override
        public long getMessagesAdded() {
            return (Integer) proxy.retrieveAttributeValue("messagesAdded", Integer.class);
        }

        @Override
        public long getMessagesAcknowledged() {
            return (Integer) proxy.retrieveAttributeValue("messagesAcknowledged", Integer.class);
        }

        @Override
        public long getMessagesExpired() {
            return (Long) proxy.retrieveAttributeValue("messagesExpired", Long.class);
        }

        @Override
        public long getMessagesKilled() {
            return ((Number) proxy.retrieveAttributeValue("messagesKilled")).longValue();
        }

        @Override
        public void resetMessagesAdded() throws Exception {
            proxy.invokeOperation("resetMessagesAdded");
        }

        @Override
        public void resetMessagesAcknowledged() throws Exception {
            proxy.invokeOperation("resetMessagesAcknowledged");
        }

        @Override
        public void resetMessagesExpired() throws Exception {
            proxy.invokeOperation("resetMessagesExpired");
        }

        @Override
        public void resetMessagesKilled() throws Exception {
            proxy.invokeOperation("resetMessagesKilled");
        }

        @Override
        public String getName() {
            return (String) proxy.retrieveAttributeValue("name");
        }

        @Override
        public long getID() {
            return (Long) proxy.retrieveAttributeValue("ID");
        }

        @Override
        public long getScheduledCount() {
            return (Long) proxy.retrieveAttributeValue("scheduledCount", Long.class);
        }

        @Override
        public long getScheduledSize() {
            return (Long) proxy.retrieveAttributeValue("scheduledSize", Long.class);
        }

        @Override
        public long getDurableScheduledCount() {
            return (Long) proxy.retrieveAttributeValue("durableScheduledCount", Long.class);
        }

        @Override
        public long getDurableScheduledSize() {
            return (Long) proxy.retrieveAttributeValue("durableScheduledSize", Long.class);
        }

        @Override
        public boolean isDurable() {
            return (Boolean) proxy.retrieveAttributeValue("durable");
        }

        @Override
        public String getRoutingType() {
            return (String) proxy.retrieveAttributeValue("routingType");
        }

        @Override
        public boolean isTemporary() {
            return (Boolean) proxy.retrieveAttributeValue("temporary");
        }

        @Override
        public String listMessageCounter() throws Exception {
            return (String) proxy.invokeOperation("listMessageCounter");
        }

        @Override
        public String listMessageCounterAsHTML() throws Exception {
            return (String) proxy.invokeOperation("listMessageCounterAsHTML");
        }

        @Override
        public String listMessageCounterHistory() throws Exception {
            return (String) proxy.invokeOperation("listMessageCounterHistory");
        }

        /**
         * Returns the first message on the queue as JSON
         */
        @Override
        public String getFirstMessageAsJSON() throws Exception {
            return (String) proxy.invokeOperation("getFirstMessageAsJSON");
        }

        /**
         * Returns the timestamp of the first message in milliseconds.
         */
        @Override
        public Long getFirstMessageTimestamp() throws Exception {
            return (Long) proxy.invokeOperation("getFirstMessageTimestamp");
        }

        /**
         * Returns the age of the first message in milliseconds.
         */
        @Override
        public Long getFirstMessageAge() throws Exception {
            return (Long) proxy.invokeOperation(Long.class, "getFirstMessageAge");
        }

        @Override
        public String listMessageCounterHistoryAsHTML() throws Exception {
            return (String) proxy.invokeOperation("listMessageCounterHistoryAsHTML");
        }

        @Override
        public Map<String, Object>[] listMessages(final String filter) throws Exception {
            Object[] res = (Object[]) proxy.invokeOperation("listMessages", filter);
            Map<String, Object>[] results = new Map[res.length];
            for (int i = 0; i < res.length; i++) {
                results[i] = (Map<String, Object>) res[i];
            }
            return results;
        }

        @Override
        public String listMessagesAsJSON(final String filter) throws Exception {
            return (String) proxy.invokeOperation("listMessagesAsJSON", filter);
        }

        @Override
        public Map<String, Object>[] listScheduledMessages() throws Exception {
            Object[] res = (Object[]) proxy.invokeOperation("listScheduledMessages");
            Map<String, Object>[] results = new Map[res.length];
            for (int i = 0; i < res.length; i++) {
                results[i] = (Map<String, Object>) res[i];
            }
            return results;
        }

        @Override
        public String listScheduledMessagesAsJSON() throws Exception {
            return (String) proxy.invokeOperation("listScheduledMessagesAsJSON");
        }

        @Override
        public int moveMessages(final String filter, final String otherQueueName) throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "moveMessages", filter, otherQueueName);
        }

        @Override
        public int moveMessages(int flushLimit, String filter, String otherQueueName, boolean rejectDuplicates) throws Exception {
            return (Integer) proxy.invokeOperation("moveMessages", flushLimit, filter, otherQueueName, rejectDuplicates);
        }

        @Override
        public int moveMessages(final String filter, final String otherQueueName, final boolean rejectDuplicates) throws Exception {
            return (Integer) proxy.invokeOperation("moveMessages", filter, otherQueueName, rejectDuplicates);
        }

        @Override
        public boolean moveMessage(final long messageID, final String otherQueueName) throws Exception {
            return (Boolean) proxy.invokeOperation("moveMessage", messageID, otherQueueName);
        }

        @Override
        public boolean moveMessage(final long messageID, final String otherQueueName, final boolean rejectDuplicates) throws Exception {
            return (Boolean) proxy.invokeOperation("moveMessage", messageID, otherQueueName, rejectDuplicates);
        }

        @Override
        public boolean retryMessage(final long messageID) throws Exception {
            return (Boolean) proxy.invokeOperation("retryMessage", messageID);
        }

        @Override
        public int retryMessages() throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "retryMessages");
        }

        @Override
        public int removeMessages(final String filter) throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "removeMessages", filter);
        }

        @Override
        public int removeMessages(final int limit, final String filter) throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "removeMessages", limit, filter);
        }

        @Override
        public int removeAllMessages() throws Exception {
            return (Integer) proxy.invokeOperation(Integer.class, "removeAllMessages");
        }

        @Override
        public boolean removeMessage(final long messageID) throws Exception {
            return (Boolean) proxy.invokeOperation("removeMessage", messageID);
        }

        @Override
        public void resetMessageCounter() throws Exception {
            proxy.invokeOperation("resetMessageCounter");
        }

        @Override
        public boolean sendMessageToDeadLetterAddress(final long messageID) throws Exception {
            return (Boolean) proxy.invokeOperation("sendMessageToDeadLetterAddress", messageID);
        }

        @Override
        public int sendMessagesToDeadLetterAddress(final String filterStr) throws Exception {
            return (Integer) proxy.invokeOperation("sendMessagesToDeadLetterAddress", filterStr);
        }

        @Override
        public String sendMessage(Map<String, String> headers, int type, String body, boolean durable, String user, String password) throws Exception {
            return (String) proxy.invokeOperation("sendMessage", headers, type, body, durable, user, password);
        }

        public void setDeadLetterAddress(final String deadLetterAddress) throws Exception {
            proxy.invokeOperation("setDeadLetterAddress", deadLetterAddress);
        }

        public void setExpiryAddress(final String expiryAddress) throws Exception {
            proxy.invokeOperation("setExpiryAddress", expiryAddress);
        }

        @Override
        public void pause() throws Exception {
            proxy.invokeOperation("pause");
        }

        @Override
        public void pause(boolean persist) throws Exception {
            proxy.invokeOperation("pause", persist);
        }

        @Override
        public void resume() throws Exception {
            proxy.invokeOperation("resume");
        }

        @Override
        public boolean isPaused() throws Exception {
            return (Boolean) proxy.invokeOperation("isPaused");
        }

        @Override
        public CompositeData[] browse() throws Exception {
            Map map = (Map) proxy.invokeOperation("browse");
            CompositeData[] compositeDatas = (CompositeData[]) map.get(CompositeData.class.getName());
            if (compositeDatas == null) {
                compositeDatas = new CompositeData[0];
            }
            return compositeDatas;
        }

        @Override
        public CompositeData[] browse(int page, int pageSize) throws Exception {
            Map map = (Map) proxy.invokeOperation("browse", page, pageSize);
            CompositeData[] compositeDatas = (CompositeData[]) map.get(CompositeData.class.getName());
            if (compositeDatas == null) {
                compositeDatas = new CompositeData[0];
            }
            return compositeDatas;
        }

        @Override
        public CompositeData[] browse(String filter) throws Exception {
            Map map = (Map) proxy.invokeOperation("browse", filter);
            CompositeData[] compositeDatas = (CompositeData[]) map.get(CompositeData.class.getName());
            if (compositeDatas == null) {
                compositeDatas = new CompositeData[0];
            }
            return compositeDatas;
        }

        @Override
        public String listConsumersAsJSON() throws Exception {
            return (String) proxy.invokeOperation("listConsumersAsJSON");
        }

        @Override
        public Map<String, Map<String, Object>[]> listDeliveringMessages() throws Exception {
            // This map code could be done better,
            // however that's just to convert stuff for the test class, so I
            // am not going to spend a lot more time on it (Clebert)
            @SuppressWarnings("rawtypes") Map res = (Map) proxy.invokeOperation("listDeliveringMessages");
            @SuppressWarnings("rawtypes") Map response = new HashMap();
            for (Object key : res.keySet()) {
                Object[] value = (Object[]) res.get(key);
                Map<String, Object>[] results = new Map[value.length];
                for (int i = 0; i < value.length; i++) {
                    results[i] = (Map<String, Object>) value[i];
                }
                response.put(key, results);
            }
            return response;
        }

        @Override
        public String listDeliveringMessagesAsJSON() throws Exception {
            return (String) proxy.invokeOperation("listDeliveringMessagesAsJSON");
        }

        @Override
        public long getPersistentSize() {
            return (Long) proxy.retrieveAttributeValue("persistentSize", Long.class);
        }

        @Override
        public long getDurableMessageCount() {
            return (Long) proxy.retrieveAttributeValue("durableMessageCount", Long.class);
        }

        @Override
        public long getDurablePersistentSize() {
            return (Long) proxy.retrieveAttributeValue("durablePersistentSize", Long.class);
        }
    };
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Map(java.util.Map) HashMap(java.util.HashMap)

Example 44 with QueueControl

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

the class ActiveMQServerControlTest method testTotalConsumerCount.

@Test
public void testTotalConsumerCount() throws Exception {
    String random1 = RandomUtil.randomString();
    String random2 = RandomUtil.randomString();
    ActiveMQServerControl serverControl = createManagementControl();
    QueueControl queueControl1 = ManagementControlHelper.createQueueControl(SimpleString.toSimpleString(random1), SimpleString.toSimpleString(random1), RoutingType.ANYCAST, mbeanServer);
    QueueControl queueControl2 = ManagementControlHelper.createQueueControl(SimpleString.toSimpleString(random2), SimpleString.toSimpleString(random2), RoutingType.ANYCAST, mbeanServer);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory csf = createSessionFactory(locator);
    ClientSession session = csf.createSession();
    session.createQueue(random1, RoutingType.ANYCAST, random1);
    session.createQueue(random2, RoutingType.ANYCAST, random2);
    ClientConsumer consumer1 = session.createConsumer(random1);
    ClientConsumer consumer2 = session.createConsumer(random2);
    assertEquals(usingCore() ? 3 : 2, serverControl.getTotalConsumerCount());
    assertEquals(1, queueControl1.getConsumerCount());
    assertEquals(1, queueControl2.getConsumerCount());
    consumer1.close();
    consumer2.close();
    session.deleteQueue(random1);
    session.deleteQueue(random2);
    session.close();
    locator.close();
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) 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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 45 with QueueControl

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

the class ActiveMQServerControlTest method testCreateAndDestroyQueueWithEmptyStringForFilter.

@Test
public void testCreateAndDestroyQueueWithEmptyStringForFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString name = RandomUtil.randomSimpleString();
    String filter = "";
    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.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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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