Search in sources :

Example 71 with Binding

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

the class ActiveMQServerTestCase method assertRemainingMessages.

protected boolean assertRemainingMessages(final int expected) throws Exception {
    String queueName = "Queue1";
    Binding binding = servers.get(0).getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName));
    if (binding != null && binding instanceof LocalQueueBinding) {
        ((LocalQueueBinding) binding).getQueue().flushExecutor();
    }
    Long messageCount = null;
    for (int i = 0; i < 10; i++) {
        messageCount = servers.get(0).getMessageCountForQueue(queueName);
        if (messageCount.longValue() == expected) {
            break;
        } else {
            Thread.sleep(100);
        }
    }
    ProxyAssertSupport.assertEquals(expected, messageCount.intValue());
    return expected == messageCount.intValue();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 72 with Binding

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

the class ScaleDownTest method testStoreAndForward.

@Test
public void testStoreAndForward() throws Exception {
    final int TEST_SIZE = 50;
    final String addressName1 = "testAddress1";
    final String addressName2 = "testAddress2";
    final String queueName1 = "testQueue1";
    final String queueName2 = "testQueue2";
    // create queues on each node mapped to 2 addresses
    createQueue(0, addressName1, queueName1, null, false);
    createQueue(1, addressName1, queueName1, null, false);
    createQueue(0, addressName2, queueName2, null, false);
    createQueue(1, addressName2, queueName2, null, false);
    // find and pause the sf queue so no messages actually move from node 0 to node 1
    String sfQueueName = null;
    for (Map.Entry<SimpleString, Binding> entry : servers[0].getPostOffice().getAllBindings().entrySet()) {
        String temp = entry.getValue().getAddress().toString();
        if (temp.startsWith(servers[1].getInternalNamingPrefix() + "sf.") && temp.endsWith(servers[1].getNodeID().toString())) {
            // we found the sf queue for the other node
            // need to pause the sfQueue here
            ((LocalQueueBinding) entry.getValue()).getQueue().pause();
            sfQueueName = temp;
        }
    }
    assertNotNull(sfQueueName);
    // send messages to node 0
    send(0, addressName1, TEST_SIZE, false, null);
    send(0, addressName2, TEST_SIZE, false, null);
    // add consumers to node 1 to force messages messages to redistribute to node 2 through the paused sf queue
    addConsumer(0, 1, queueName1, null);
    addConsumer(1, 1, queueName2, null);
    LocalQueueBinding queue1Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName1)));
    LocalQueueBinding queue2Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName2)));
    LocalQueueBinding sfQueueBinding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(sfQueueName)));
    long timeout = 5000;
    long start = System.currentTimeMillis();
    while (getMessageCount(queue1Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
        Thread.sleep(50);
    }
    start = System.currentTimeMillis();
    while (getMessageCount(queue2Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
        Thread.sleep(50);
    }
    start = System.currentTimeMillis();
    while (getMessageCount(sfQueueBinding.getQueue()) < TEST_SIZE * 2 && System.currentTimeMillis() - start <= timeout) {
        Thread.sleep(50);
    }
    // at this point on node 0 there should be 0 messages in test queues and TEST_SIZE * 2 messages in the sf queue
    Assert.assertEquals(0, getMessageCount(queue1Binding.getQueue()));
    Assert.assertEquals(0, getMessageCount(queue2Binding.getQueue()));
    Assert.assertEquals(TEST_SIZE * 2, getMessageCount(sfQueueBinding.getQueue()));
    removeConsumer(0);
    removeConsumer(1);
    // trigger scaleDown from node 0 to node 1
    servers[0].stop();
    // get the messages from node 1
    addConsumer(0, 1, queueName1, null);
    for (int i = 0; i < TEST_SIZE; i++) {
        ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
        Assert.assertNotNull(clientMessage);
        clientMessage.acknowledge();
    }
    ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
    addConsumer(0, 1, queueName2, null);
    for (int i = 0; i < TEST_SIZE; i++) {
        clientMessage = consumers[0].getConsumer().receive(250);
        Assert.assertNotNull(clientMessage);
        clientMessage.acknowledge();
    }
    clientMessage = consumers[0].getConsumer().receive(250);
    Assert.assertNull(clientMessage);
    removeConsumer(0);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) 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) Map(java.util.Map) Test(org.junit.Test)

Example 73 with Binding

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

the class JMSServerManagerImpl method destroyTopic.

@Override
public synchronized boolean destroyTopic(final String name, final boolean removeConsumers) throws Exception {
    checkInitialised();
    AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.ADDRESS + name);
    if (addressControl != null) {
        for (String queueName : addressControl.getQueueNames()) {
            Binding binding = server.getPostOffice().getBinding(new SimpleString(queueName));
            if (binding == null) {
                ActiveMQJMSServerLogger.LOGGER.noQueueOnTopic(queueName, name);
                continue;
            }
            // We can't remove the remote binding. As this would be the bridge associated with the topic on this case
            if (binding.getType() != BindingType.REMOTE_QUEUE) {
                server.destroyQueue(SimpleString.toSimpleString(queueName), null, !removeConsumers, removeConsumers, true);
            }
        }
        if (addressControl.getQueueNames().length == 0) {
            try {
                server.removeAddressInfo(SimpleString.toSimpleString(name), null);
            } catch (ActiveMQAddressDoesNotExistException e) {
            // ignore
            }
            removeFromBindings(topics, topicBindings, name);
            topics.remove(name);
            topicBindings.remove(name);
            storage.deleteDestination(PersistedType.Topic, name);
            sendNotification(JMSNotificationType.TOPIC_DESTROYED, name);
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) Binding(org.apache.activemq.artemis.core.postoffice.Binding) ActiveMQAddressDoesNotExistException(org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 74 with Binding

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

the class QueueImpl method moveBetweenSnFQueues.

@SuppressWarnings({ "ArrayToString", "ArrayToStringConcatenation" })
private void moveBetweenSnFQueues(final SimpleString queueSuffix, final Transaction tx, final MessageReference ref) throws Exception {
    Message copyMessage = makeCopy(ref, false, false);
    byte[] oldRouteToIDs = null;
    String targetNodeID;
    Binding targetBinding;
    // remove the old route
    for (SimpleString propName : copyMessage.getPropertyNames()) {
        if (propName.startsWith(Message.HDR_ROUTE_TO_IDS)) {
            oldRouteToIDs = (byte[]) copyMessage.removeProperty(propName.toString());
            // don't use Arrays.toString(..) here
            final String hashcodeToString = oldRouteToIDs.toString();
            logger.debug("Removed property from message: " + propName + " = " + hashcodeToString + " (" + ByteBuffer.wrap(oldRouteToIDs).getLong() + ")");
            // there should only be one of these properties so potentially save some loop iterations
            break;
        }
    }
    ByteBuffer oldBuffer = ByteBuffer.wrap(oldRouteToIDs);
    RoutingContext routingContext = new RoutingContextImpl(tx);
    /* this algorithm will look at the old route and find the new remote queue bindings where the messages should go
       * and route them there directly
       */
    while (oldBuffer.hasRemaining()) {
        long oldQueueID = oldBuffer.getLong();
        // look at all the bindings
        Pair<String, Binding> result = locateTargetBinding(queueSuffix, copyMessage, oldQueueID);
        targetBinding = result.getB();
        targetNodeID = result.getA();
        if (targetBinding == null) {
            ActiveMQServerLogger.LOGGER.unableToFindTargetQueue(targetNodeID);
        } else {
            logger.debug("Routing on binding: " + targetBinding);
            targetBinding.route(copyMessage, routingContext);
        }
    }
    postOffice.processRoute(copyMessage, routingContext, false);
    ref.handled();
    acknowledge(tx, ref);
    storageManager.afterCompleteOperations(new IOCallback() {

        @Override
        public void onError(final int errorCode, final String errorMessage) {
            ActiveMQServerLogger.LOGGER.ioErrorRedistributing(errorCode, errorMessage);
        }

        @Override
        public void done() {
            deliverAsync();
        }
    });
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext)

Example 75 with Binding

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

the class ServerSessionImpl method deleteQueue.

@Override
public void deleteQueue(final SimpleString queueToDelete) throws Exception {
    final SimpleString unPrefixedQueueName = removePrefix(queueToDelete);
    Binding binding = postOffice.getBinding(unPrefixedQueueName);
    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw new ActiveMQNonExistentQueueException();
    }
    server.destroyQueue(unPrefixedQueueName, this, true);
    TempQueueCleanerUpper cleaner = this.tempQueueCleannerUppers.remove(unPrefixedQueueName);
    if (cleaner != null) {
        remotingConnection.removeCloseListener(cleaner);
        remotingConnection.removeFailureListener(cleaner);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)

Aggregations

Binding (org.apache.activemq.artemis.core.postoffice.Binding)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)52 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)29 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)28 Test (org.junit.Test)25 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)24 Queue (org.apache.activemq.artemis.core.server.Queue)24 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)18 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)17 ArrayList (java.util.ArrayList)12 Filter (org.apache.activemq.artemis.core.filter.Filter)10 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)9 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)7 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7