Search in sources :

Example 1 with RemoteQueueBinding

use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.

the class BindingsImpl method route.

private void route(final Message message, final RoutingContext context, final boolean groupRouting) throws Exception {
    /* This is a special treatment for scaled-down messages involving SnF queues.
       * See org.apache.activemq.artemis.core.server.impl.ScaleDownHandler.scaleDownMessages() for the logic that sends messages with this property
       */
    byte[] ids = (byte[]) message.removeExtraBytesProperty(Message.HDR_SCALEDOWN_TO_IDS);
    if (ids != null) {
        ByteBuffer buffer = ByteBuffer.wrap(ids);
        while (buffer.hasRemaining()) {
            long id = buffer.getLong();
            for (Map.Entry<Long, Binding> entry : bindingsMap.entrySet()) {
                if (entry.getValue() instanceof RemoteQueueBinding) {
                    RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) entry.getValue();
                    if (remoteQueueBinding.getRemoteQueueID() == id) {
                        message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, ByteBuffer.allocate(8).putLong(remoteQueueBinding.getID()).array());
                    }
                }
            }
        }
    }
    boolean routed = false;
    for (Binding binding : exclusiveBindings) {
        if (binding.getFilter() == null || binding.getFilter().match(message)) {
            binding.getBindable().route(message, context);
            routed = true;
        }
    }
    if (!routed) {
        // Remove the ids now, in order to avoid double check
        ids = message.removeExtraBytesProperty(Message.HDR_ROUTE_TO_IDS);
        // Fetch the groupId now, in order to avoid double checking
        SimpleString groupId = message.getGroupID();
        if (ids != null) {
            routeFromCluster(message, context, ids);
        } else if (groupingHandler != null && groupRouting && groupId != null) {
            routeUsingStrictOrdering(message, context, groupingHandler, groupId, 0);
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("Routing message " + message + " on binding=" + this);
            }
            for (Map.Entry<SimpleString, List<Binding>> entry : routingNameBindingMap.entrySet()) {
                SimpleString routingName = entry.getKey();
                List<Binding> bindings = entry.getValue();
                if (bindings == null) {
                    // ConcurrentHashMap behaviour!
                    continue;
                }
                Binding theBinding = getNextBinding(message, routingName, bindings);
                if (theBinding != null) {
                    theBinding.route(message, context);
                }
            }
        }
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ByteBuffer(java.nio.ByteBuffer) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Example 2 with RemoteQueueBinding

use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.

the class QueueImpl method locateTargetBinding.

private Pair<String, Binding> locateTargetBinding(SimpleString queueSuffix, Message copyMessage, long oldQueueID) {
    String targetNodeID = null;
    Binding targetBinding = null;
    for (Map.Entry<SimpleString, Binding> entry : postOffice.getAllBindings().entrySet()) {
        Binding binding = entry.getValue();
        // we only care about the remote queue bindings
        if (binding instanceof RemoteQueueBinding) {
            RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) binding;
            // does this remote queue binding point to the same queue as the message?
            if (oldQueueID == remoteQueueBinding.getRemoteQueueID()) {
                // get the name of this queue so we can find the corresponding remote queue binding pointing to the scale down target node
                SimpleString oldQueueName = remoteQueueBinding.getRoutingName();
                // parse the queue name of the remote queue binding to determine the node ID
                String temp = remoteQueueBinding.getQueue().getName().toString();
                targetNodeID = temp.substring(temp.lastIndexOf(".") + 1);
                logger.debug("Message formerly destined for " + oldQueueName + " with ID: " + oldQueueID + " on address " + copyMessage.getAddressSimpleString() + " on node " + targetNodeID);
                // now that we have the name of the queue we need to look through all the bindings again to find the new remote queue binding
                for (Map.Entry<SimpleString, Binding> entry2 : postOffice.getAllBindings().entrySet()) {
                    binding = entry2.getValue();
                    // again, we only care about the remote queue bindings
                    if (binding instanceof RemoteQueueBinding) {
                        remoteQueueBinding = (RemoteQueueBinding) binding;
                        temp = remoteQueueBinding.getQueue().getName().toString();
                        targetNodeID = temp.substring(temp.lastIndexOf(".") + 1);
                        if (oldQueueName.equals(remoteQueueBinding.getRoutingName()) && targetNodeID.equals(queueSuffix.toString())) {
                            targetBinding = remoteQueueBinding;
                            if (logger.isDebugEnabled()) {
                                logger.debug("Message now destined for " + remoteQueueBinding.getRoutingName() + " with ID: " + remoteQueueBinding.getRemoteQueueID() + " on address " + copyMessage.getAddress() + " on node " + targetNodeID);
                            }
                            break;
                        } else {
                            logger.debug("Failed to match: " + remoteQueueBinding);
                        }
                    }
                }
            }
        }
    }
    return new Pair<>(targetNodeID, targetBinding);
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Map(java.util.Map) HashMap(java.util.HashMap) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 3 with RemoteQueueBinding

use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.

the class ClusterTestBase method waitForBindings.

protected void waitForBindings(final int node, final String address, final int expectedBindingCount, final int expectedConsumerCount, final boolean local) throws Exception {
    log.debug("waiting for bindings on node " + node + " address " + address + " expectedBindingCount " + expectedBindingCount + " consumerCount " + expectedConsumerCount + " local " + local);
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    long timeout = ActiveMQTestBase.WAIT_TIMEOUT;
    if (waitForBindings(server, address, local, expectedBindingCount, expectedConsumerCount, timeout)) {
        return;
    }
    PostOffice po = server.getPostOffice();
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    System.out.println("=======================================================================");
    System.out.println("Binding information for address = " + address + " on node " + node);
    for (Binding binding : bindings.getBindings()) {
        if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
            QueueBinding qBinding = (QueueBinding) binding;
            System.out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
        }
    }
    StringWriter writer = new StringWriter();
    PrintWriter out = new PrintWriter(writer);
    try {
        for (ActiveMQServer activeMQServer : servers) {
            if (activeMQServer != null) {
                out.println(clusterDescription(activeMQServer));
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
        for (ActiveMQServer activeMQServer : servers) {
            out.println("Management bindings on " + activeMQServer);
            if (activeMQServer != null) {
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
    } catch (Throwable dontCare) {
    }
    logAndSystemOut(writer.toString());
    throw new IllegalStateException("Didn't get the expected number of bindings, look at the logging for more information");
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) StringWriter(java.io.StringWriter) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PrintWriter(java.io.PrintWriter)

Example 4 with RemoteQueueBinding

use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.

the class ActiveMQTestBase method waitForBindings.

/**
 * @param server                the server where's being checked
 * @param address               the name of the address being checked
 * @param local                 if true we are looking for local bindings, false we are looking for remoting servers
 * @param expectedBindingCount  the expected number of counts
 * @param expectedConsumerCount the expected number of consumers
 * @param timeout               the timeout used on the check
 * @return
 * @throws Exception
 * @throws InterruptedException
 */
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
    final PostOffice po = server.getPostOffice();
    long start = System.currentTimeMillis();
    int bindingCount = 0;
    int totConsumers = 0;
    do {
        bindingCount = 0;
        totConsumers = 0;
        Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
        for (Binding binding : bindings.getBindings()) {
            if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
                QueueBinding qBinding = (QueueBinding) binding;
                bindingCount++;
                totConsumers += qBinding.consumerCount();
            }
        }
        if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
            return true;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < timeout);
    String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
    log.error(msg);
    return false;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Example 5 with RemoteQueueBinding

use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.

the class MessageRedistributionTest method getRemoteQueueBinding.

private RemoteQueueBinding getRemoteQueueBinding(ActiveMQServer server) throws Exception {
    ActiveMQServer remoteServer = server;
    Bindings bindings = remoteServer.getPostOffice().getBindingsForAddress(new SimpleString("queues.testaddress"));
    Collection<Binding> bindingSet = bindings.getBindings();
    return getRemoteQueueBinding(bindingSet);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Aggregations

RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)6 Binding (org.apache.activemq.artemis.core.postoffice.Binding)6 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)3 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)3 Map (java.util.Map)2 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)2 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Connection (javax.jms.Connection)1