Search in sources :

Example 11 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class StompTest method testSubscribeToNonExistentQueue.

@Test
public void testSubscribeToNonExistentQueue() throws Exception {
    String nonExistentQueue = RandomUtil.randomString();
    conn.connect(defUser, defPass);
    subscribe(conn, null, null, null, null, getQueuePrefix() + nonExistentQueue, true);
    sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue));
    ClientStompFrame frame = conn.receiveFrame(1000);
    Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
    Assert.assertEquals(getQueuePrefix() + nonExistentQueue, frame.getHeader(Stomp.Headers.Send.DESTINATION));
    Assert.assertEquals(getName(), frame.getBody());
    assertNotNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue)));
    final Queue subscription = ((LocalQueueBinding) server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue))).getQueue();
    assertTrue(Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisfied() throws Exception {
            if (subscription.getMessageCount() == 0)
                return true;
            else
                return false;
        }
    }, 1000, 50));
    unsubscribe(conn, null, getQueuePrefix() + nonExistentQueue, true, false);
    assertNull(server.getActiveMQServer().getPostOffice().getBinding(new SimpleString(nonExistentQueue)));
    sendJmsMessage(getName(), ActiveMQJMSClient.createQueue(nonExistentQueue));
    frame = conn.receiveFrame(1000);
    log.info("Received frame: " + frame);
    Assert.assertNull("No message should have been received since subscription was removed", frame);
    conn.disconnect();
}
Also used : ClientStompFrame(org.apache.activemq.artemis.tests.integration.stomp.util.ClientStompFrame) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 12 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ScaleDownDirectTest method testBasicScaleDown.

@Test
public void testBasicScaleDown() throws Exception {
    final int TEST_SIZE = 2;
    final String addressName = "testAddress";
    final String queueName1 = "testQueue1";
    final String queueName2 = "testQueue2";
    // create 2 queues on each node mapped to the same address
    createQueue(0, addressName, queueName1, null, true);
    createQueue(0, addressName, queueName2, null, true);
    createQueue(1, addressName, queueName1, null, true);
    createQueue(1, addressName, queueName2, null, true);
    // send messages to node 0
    send(0, addressName, TEST_SIZE, true, null);
    // consume a message from queue 2
    addConsumer(1, 0, queueName2, null, false);
    ClientMessage clientMessage = consumers[1].getConsumer().receive(250);
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    consumers[1].getSession().commit();
    removeConsumer(1);
    // at this point on node 0 there should be 2 messages in testQueue1 and 1 message in testQueue2
    Assert.assertEquals(TEST_SIZE, getMessageCount(((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue()));
    Assert.assertEquals(TEST_SIZE - 1, getMessageCount(((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName2))).getQueue()));
    assertEquals(TEST_SIZE, performScaledown());
    // trigger scaleDown from node 0 to node 1
    servers[0].stop();
    // get the 2 messages from queue 1
    addConsumer(0, 1, queueName1, null);
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    // ensure there are no more messages on queue 1
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
    // get the 1 message from queue 2
    addConsumer(0, 1, queueName2, null);
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNotNull(clientMessage);
    clientMessage.acknowledge();
    // ensure there are no more messages on queue 1
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
}
Also used : LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) 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) Test(org.junit.Test)

Example 13 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ScaleDown3NodeTest method testScaleDownWithMultipleQueues.

@Test
public void testScaleDownWithMultipleQueues() throws Exception {
    AddressSettings addressSettings = new AddressSettings().setRedistributionDelay(0);
    servers[0].getAddressSettingsRepository().addMatch("#", addressSettings);
    servers[1].getAddressSettingsRepository().addMatch("#", addressSettings);
    servers[2].getAddressSettingsRepository().addMatch("#", addressSettings);
    final int TEST_SIZE = 10;
    final String addressName = "testAddress";
    final String queueName1 = "testQueue1";
    final String queueName2 = "testQueue2";
    final String queueName3 = "testQueue3";
    // create a queue on each node mapped to the same address
    createQueue(0, addressName, queueName1, null, false, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    createQueue(1, addressName, queueName1, null, false, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    createQueue(2, addressName, queueName1, null, false, servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword());
    // create a queue on each node mapped to the same address
    createQueue(0, addressName, queueName2, null, false, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    createQueue(1, addressName, queueName2, null, false, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    createQueue(2, addressName, queueName2, null, false, servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword());
    // create a queue on each node mapped to the same address
    createQueue(0, addressName, queueName3, null, false, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    createQueue(1, addressName, queueName3, null, false, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    createQueue(2, addressName, queueName3, null, false, servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword());
    // pause the SnF queue so that when the server tries to redistribute a message it won't actually go across the cluster bridge
    String snfAddress = servers[0].getInternalNamingPrefix() + "sf.cluster0." + servers[0].getNodeID().toString();
    Queue snfQueue = ((LocalQueueBinding) servers[2].getPostOffice().getBinding(SimpleString.toSimpleString(snfAddress))).getQueue();
    snfQueue.pause();
    ClientSession session = sfs[2].createSession(servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword(), false, true, false, false, 0);
    Message message;
    message = session.createMessage(false);
    for (int i = 0; i < TEST_SIZE; i++) {
        ClientProducer producer = session.createProducer(addressName);
        producer.send(message);
    }
    // add a consumer to node 0 to trigger redistribution here
    addConsumer(0, 0, queueName1, null, true, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    addConsumer(1, 0, queueName3, null, true, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    // allow some time for redistribution to move the message to the SnF queue
    long timeout = 10000;
    long start = System.currentTimeMillis();
    long messageCount = 0;
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the message is not in the queue on node 2
        messageCount = getMessageCount(snfQueue);
        if (messageCount < TEST_SIZE * 2) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    // ensure the message is in the SnF queue
    Assert.assertEquals(TEST_SIZE * 2, getMessageCount(snfQueue));
    // trigger scaleDown from node 0 to node 1
    IntegrationTestLogger.LOGGER.info("============ Stopping " + servers[0].getNodeID());
    removeConsumer(0);
    removeConsumer(1);
    servers[0].stop();
    start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the messages are not in the queues on node 2
        messageCount = getMessageCount(((LocalQueueBinding) servers[2].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue());
        messageCount += getMessageCount(((LocalQueueBinding) servers[2].getPostOffice().getBinding(new SimpleString(queueName3))).getQueue());
        if (messageCount > 0) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    Assert.assertEquals(0, messageCount);
    Assert.assertEquals(TEST_SIZE, getMessageCount(((LocalQueueBinding) servers[2].getPostOffice().getBinding(new SimpleString(queueName2))).getQueue()));
    // get the messages from queue 1 on node 1
    addConsumer(0, 1, queueName1, null, true, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    addConsumer(1, 1, queueName3, null, true, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    // allow some time for redistribution to move the message to node 1
    start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the message is not in the queue on node 2
        messageCount = getMessageCount(((LocalQueueBinding) servers[1].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue());
        messageCount += getMessageCount(((LocalQueueBinding) servers[1].getPostOffice().getBinding(new SimpleString(queueName3))).getQueue());
        if (messageCount < TEST_SIZE * 2) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    // ensure the message is in queue 1 on node 1 as expected
    Assert.assertEquals(TEST_SIZE * 2, messageCount);
    for (int i = 0; i < TEST_SIZE; i++) {
        ClientMessage clientMessage = consumers[0].getConsumer().receive(1000);
        Assert.assertNotNull(clientMessage);
        IntegrationTestLogger.LOGGER.info("Received: " + clientMessage);
        clientMessage.acknowledge();
        clientMessage = consumers[1].getConsumer().receive(1000);
        Assert.assertNotNull(clientMessage);
        IntegrationTestLogger.LOGGER.info("Received: " + clientMessage);
        clientMessage.acknowledge();
    }
    // ensure there are no more messages on queue 1
    ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
    // ensure there are no more messages on queue 3
    clientMessage = consumers[1].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(1);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 14 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class ScaleDown3NodeTest method testBasicScaleDownInternal.

private void testBasicScaleDownInternal(int reconnectAttempts, boolean large) throws Exception {
    AddressSettings addressSettings = new AddressSettings().setRedistributionDelay(0);
    servers[0].getAddressSettingsRepository().addMatch("#", addressSettings);
    servers[1].getAddressSettingsRepository().addMatch("#", addressSettings);
    servers[2].getAddressSettingsRepository().addMatch("#", addressSettings);
    servers[0].getConfiguration().getClusterConfigurations().get(0).setReconnectAttempts(reconnectAttempts);
    servers[1].getConfiguration().getClusterConfigurations().get(0).setReconnectAttempts(reconnectAttempts);
    servers[2].getConfiguration().getClusterConfigurations().get(0).setReconnectAttempts(reconnectAttempts);
    final int TEST_SIZE = 10;
    final String addressName = "testAddress";
    final String queueName1 = "testQueue1";
    // create a queue on each node mapped to the same address
    createQueue(0, addressName, queueName1, null, false, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    createQueue(1, addressName, queueName1, null, false, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    createQueue(2, addressName, queueName1, null, false, servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword());
    // pause the SnF queue so that when the server tries to redistribute a message it won't actually go across the cluster bridge
    String snfAddress = servers[0].getInternalNamingPrefix() + "sf.cluster0." + servers[0].getNodeID().toString();
    Queue snfQueue = ((LocalQueueBinding) servers[2].getPostOffice().getBinding(SimpleString.toSimpleString(snfAddress))).getQueue();
    snfQueue.pause();
    ClientSession session = sfs[2].createSession(servers[2].getConfiguration().getClusterUser(), servers[2].getConfiguration().getClusterPassword(), false, true, false, false, 0);
    Message message;
    if (large) {
        LargeServerMessageImpl fileMessage = new LargeServerMessageImpl((JournalStorageManager) servers[2].getStorageManager());
        fileMessage.setMessageID(1005);
        fileMessage.setDurable(true);
        for (int i = 0; i < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; i++) {
            fileMessage.addBytes(new byte[] { ActiveMQTestBase.getSamplebyte(i) });
        }
        fileMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
        fileMessage.releaseResources();
        message = fileMessage;
    } else {
        message = session.createMessage(false);
    }
    for (int i = 0; i < TEST_SIZE; i++) {
        ClientProducer producer = session.createProducer(addressName);
        producer.send(message);
    }
    if (large) {
        ((LargeServerMessageImpl) message).deleteFile();
    }
    // add a consumer to node 0 to trigger redistribution here
    addConsumer(0, 0, queueName1, null, true, servers[0].getConfiguration().getClusterUser(), servers[0].getConfiguration().getClusterPassword());
    // allow some time for redistribution to move the message to the SnF queue
    long timeout = 10000;
    long start = System.currentTimeMillis();
    long messageCount = 0;
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the message is not in the queue on node 2
        messageCount = getMessageCount(snfQueue);
        if (messageCount < TEST_SIZE) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    // ensure the message is in the SnF queue
    Assert.assertEquals(TEST_SIZE, getMessageCount(snfQueue));
    // trigger scaleDown from node 0 to node 1
    IntegrationTestLogger.LOGGER.info("============ Stopping " + servers[0].getNodeID());
    removeConsumer(0);
    servers[0].stop();
    start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the message is not in the queue on node 2
        messageCount = getMessageCount(((LocalQueueBinding) servers[2].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue());
        if (messageCount > 0) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    Assert.assertEquals(0, messageCount);
    // get the messages from queue 1 on node 1
    addConsumer(0, 1, queueName1, null, true, servers[1].getConfiguration().getClusterUser(), servers[1].getConfiguration().getClusterPassword());
    // allow some time for redistribution to move the message to node 1
    start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout) {
        // ensure the message is not in the queue on node 2
        messageCount = getMessageCount(((LocalQueueBinding) servers[1].getPostOffice().getBinding(new SimpleString(queueName1))).getQueue());
        if (messageCount < TEST_SIZE) {
            Thread.sleep(200);
        } else {
            break;
        }
    }
    // ensure the message is in queue 1 on node 1 as expected
    Assert.assertEquals(TEST_SIZE, messageCount);
    for (int i = 0; i < TEST_SIZE; i++) {
        ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
        Assert.assertNotNull(clientMessage);
        if (large) {
            Assert.assertEquals(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, clientMessage.getBodySize());
            for (int j = 0; j < 2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE; j++) {
                Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), clientMessage.getBodyBuffer().readByte());
            }
        }
        IntegrationTestLogger.LOGGER.info("Received: " + clientMessage);
        clientMessage.acknowledge();
    }
    // ensure there are no more messages on queue 1
    ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) LargeServerMessageImpl(org.apache.activemq.artemis.core.persistence.impl.journal.LargeServerMessageImpl) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 15 with LocalQueueBinding

use of org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding in project activemq-artemis by apache.

the class AmqpFullyQualifiedNameTest method testTopic.

@Test(timeout = 60000)
public // however we can test query functionality
void testTopic() throws Exception {
    SimpleString queueName = new SimpleString("someAddress");
    server.createQueue(multicastAddress, RoutingType.MULTICAST, queueName, null, false, false);
    Connection connection = createConnection(false);
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic fqqn = session.createTopic(multicastAddress.toString() + "::" + queueName);
        MessageConsumer consumer1 = session.createConsumer(fqqn);
        MessageConsumer consumer2 = session.createConsumer(fqqn);
        Topic topic = session.createTopic(multicastAddress.toString());
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createMessage());
        // each consumer receives one
        Message m = consumer1.receive(2000);
        assertNotNull(m);
        // Subscribing to FQQN is akin to shared subscription
        m = consumer2.receive(2000);
        assertNull(m);
        Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
        for (Binding b : bindings.getBindings()) {
            System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
            SimpleString qName = b.getUniqueName();
            // do FQQN query
            QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
            assertTrue(result.isExists());
            assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
            // do qname query
            result = server.queueQuery(qName);
            assertTrue(result.isExists());
            assertEquals(result.getName(), qName);
        }
    } finally {
        connection.close();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Topic(javax.jms.Topic) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)22 Binding (org.apache.activemq.artemis.core.postoffice.Binding)19 Test (org.junit.Test)18 Queue (org.apache.activemq.artemis.core.server.Queue)14 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 PostOfficeImpl (org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)4 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3