Search in sources :

Example 16 with Bindings

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

the class BindingsImplTest method internalTest.

private void internalTest(final boolean route) throws Exception {
    final FakeBinding fake = new FakeBinding(new SimpleString("a"));
    final Bindings bind = new BindingsImpl(null, null, null);
    bind.addBinding(fake);
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    bind.addBinding(new FakeBinding(new SimpleString("a")));
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                bind.removeBinding(fake);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    Queue queue = new FakeQueue(new SimpleString("a"));
    t.start();
    for (int i = 0; i < 100; i++) {
        if (route) {
            bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
        } else {
            bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
        }
    }
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 17 with Bindings

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

the class QueueImpl method sendToDeadLetterAddress.

private void sendToDeadLetterAddress(final Transaction tx, final MessageReference ref, final SimpleString deadLetterAddress) throws Exception {
    if (deadLetterAddress != null) {
        Bindings bindingList = postOffice.getBindingsForAddress(deadLetterAddress);
        if (bindingList.getBindings().isEmpty()) {
            ActiveMQServerLogger.LOGGER.messageExceededMaxDelivery(ref, deadLetterAddress);
            ref.acknowledge(tx, AckReason.KILLED);
        } else {
            ActiveMQServerLogger.LOGGER.messageExceededMaxDeliverySendtoDLA(ref, deadLetterAddress, name);
            move(tx, deadLetterAddress, null, ref, false, AckReason.KILLED);
        }
    } else {
        ActiveMQServerLogger.LOGGER.messageExceededMaxDeliveryNoDLA(ref, name);
        ref.acknowledge(tx, AckReason.KILLED);
    }
}
Also used : Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 18 with Bindings

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

the class ScaleDownHandler method scaleDownMessages.

public long scaleDownMessages(ClientSessionFactory sessionFactory, SimpleString nodeId, String user, String password) throws Exception {
    long messageCount = 0;
    targetNodeId = nodeId != null ? nodeId.toString() : getTargetNodeId(sessionFactory);
    try (ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, 0)) {
        ClientProducer producer = session.createProducer();
        // perform a loop per address
        for (SimpleString address : postOffice.getAddresses()) {
            logger.debug("Scaling down address " + address);
            Bindings bindings = postOffice.getBindingsForAddress(address);
            // It will get a list of queues on this address, ordered by the number of messages
            Set<Queue> queues = new TreeSet<>(new OrderQueueByNumberOfReferencesComparator());
            for (Binding binding : bindings.getBindings()) {
                if (binding instanceof LocalQueueBinding) {
                    Queue queue = ((LocalQueueBinding) binding).getQueue();
                    // as part of scale down we will cancel any scheduled message and pass it to theWhile we scan for the queues we will also cancel any scheduled messages and deliver them right away
                    queue.deliverScheduledMessages();
                    queues.add(queue);
                }
            }
            String sfPrefix = ((PostOfficeImpl) postOffice).getServer().getInternalNamingPrefix() + "sf.";
            if (address.toString().startsWith(sfPrefix)) {
                messageCount += scaleDownSNF(address, queues, producer);
            } else {
                messageCount += scaleDownRegularMessages(address, queues, session, producer);
            }
        }
    }
    return messageCount;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) 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) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) TreeSet(java.util.TreeSet) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Example 19 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings 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 20 with Bindings

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

the class ClusterTestBase method debugBindings.

protected String debugBindings(final ActiveMQServer server, final String address) throws Exception {
    StringWriter str = new StringWriter();
    PrintWriter out = new PrintWriter(str);
    if (server == null) {
        return "server is shutdown";
    }
    PostOffice po = server.getPostOffice();
    if (po == null) {
        return "server is shutdown";
    }
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    out.println("=======================================================================");
    out.println("Binding information for address = " + address + " on " + server);
    for (Binding binding : bindings.getBindings()) {
        QueueBinding qBinding = (QueueBinding) binding;
        out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
    }
    out.println("=======================================================================");
    return str.toString();
}
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) StringWriter(java.io.StringWriter) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) PrintWriter(java.io.PrintWriter)

Aggregations

Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)35 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)24 Binding (org.apache.activemq.artemis.core.postoffice.Binding)22 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)15 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 Test (org.junit.Test)7 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Queue (org.apache.activemq.artemis.core.server.Queue)6 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)6 ArrayList (java.util.ArrayList)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 Connection (javax.jms.Connection)4 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)4 Address (org.apache.activemq.artemis.core.postoffice.Address)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 MessageConsumer (javax.jms.MessageConsumer)3