Search in sources :

Example 61 with QueueControl

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

the class AddressControlImpl method getQueues.

private List<QueueControl> getQueues(final DurabilityType durability) {
    try {
        List<QueueControl> matchingQueues = new ArrayList<>();
        String[] queues = getQueueNames();
        for (String queue : queues) {
            QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queue);
            // Ignore the "special" subscription
            if (coreQueueControl != null) {
                if (durability == DurabilityType.ALL || durability == DurabilityType.DURABLE && coreQueueControl.isDurable() || durability == DurabilityType.NON_DURABLE && !coreQueueControl.isDurable()) {
                    matchingQueues.add(coreQueueControl);
                }
            }
        }
        return matchingQueues;
    } catch (Exception e) {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 62 with QueueControl

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

the class AddressControlImpl method getMessageCount.

// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
private long getMessageCount(final DurabilityType durability) {
    List<QueueControl> queues = getQueues(durability);
    long count = 0;
    for (QueueControl queue : queues) {
        count += queue.getMessageCount();
    }
    return count;
}
Also used : QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 63 with QueueControl

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

the class BasicXaRecoveryTest method checkQueueDeliveryCount.

private void checkQueueDeliveryCount(SimpleString thequeue, int expectedCount) throws Exception {
    QueueControl queueControl = ManagementControlHelper.createQueueControl(thequeue, thequeue, mbeanServer);
    int actualCount = queueControl.getDeliveringCount();
    assertEquals(expectedCount, actualCount);
}
Also used : QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 64 with QueueControl

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

the class ClusteredMessageCounterTest method testMessageAddedWithPaging.

// messages flow from one node to another, in paging mode
// check the messageAdded is correct.
private void testMessageAddedWithPaging(boolean durable) throws Exception {
    startServers(0, 1);
    numMsg = 100;
    try {
        setupSessionFactory(0, isNetty());
        setupSessionFactory(1, isNetty());
        createQueue(0, "queues", "queue0", null, false);
        createQueue(1, "queues", "queue0", null, false);
        waitForBindings(1, "queues", 1, 0, true);
        waitForBindings(0, "queues", 1, 0, false);
        addConsumer(1, 1, "queue0", null);
        waitForBindings(0, "queues", 1, 1, false);
        System.out.println("sending.....");
        send(0, "queues", numMsg, durable, null);
        verifyReceiveAllOnSingleConsumer(true, 0, numMsg, 1);
        QueueControl control = (QueueControl) servers[1].getManagementService().getResource(ResourceNames.QUEUE + "queue0");
        // wait up to 30sec to allow the counter get updated
        long timeout = 30000;
        while (timeout > 0 && (numMsg != control.getMessagesAdded())) {
            Thread.sleep(1000);
            timeout -= 1000;
        }
        assertEquals(numMsg, control.getMessagesAdded());
    } finally {
        stopServers(0, 1);
    }
}
Also used : QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 65 with QueueControl

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

the class BridgeReconnectTest method testReconnectSameNode.

// Fail bridge and reconnect same node, no backup specified
@Test
public void testReconnectSameNode() throws Exception {
    server0 = createActiveMQServer(0, isNetty(), server0Params);
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");
    server0.getConfiguration().setConnectorConfigurations(connectors);
    server1.getConfiguration().setConnectorConfigurations(connectors);
    BridgeConfiguration bridgeConfiguration = createBridgeConfig();
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    startServers();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithHA(server0tc, server1tc));
    ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
    session0 = csf0.createSession(false, true, true);
    ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
    session1 = csf1.createSession(false, true, true);
    ClientProducer prod0 = session0.createProducer(testAddress);
    ClientConsumer cons1 = session1.createConsumer(queueName);
    session1.start();
    // Now we will simulate a failure of the bridge connection between server0 and server1
    Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
    assertNotNull(bridge);
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    InVMConnector.failOnCreateConnection = true;
    InVMConnector.numberOfFailures = reconnectAttempts - 1;
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    final ManagementService managementService = server0.getManagementService();
    QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queueName);
    assertEquals(0, coreQueueControl.getDeliveringCount());
    final int numMessages = NUM_MESSAGES;
    SimpleString propKey = new SimpleString("propkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(false);
        message.putIntProperty(propKey, i);
        prod0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage r1 = cons1.receive(1500);
        assertNotNull(r1);
        assertEquals(i, r1.getObjectProperty(propKey));
    }
    closeServers();
    assertNoMoreConnections();
}
Also used : BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Bridge(org.apache.activemq.artemis.core.server.cluster.Bridge) 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