Search in sources :

Example 1 with Bindings

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

the class PostOfficeImpl method removeAddressInfo.

@Override
public AddressInfo removeAddressInfo(SimpleString address, boolean force) throws Exception {
    synchronized (addressLock) {
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.beforeRemoveAddress(address));
        }
        final Bindings bindingsForAddress = getDirectBindings(address);
        if (force) {
            for (Binding binding : bindingsForAddress.getBindings()) {
                if (binding instanceof QueueBinding) {
                    ((QueueBinding) binding).getQueue().deleteQueue(true);
                }
            }
        } else {
            if (bindingsForAddress.getBindings().size() > 0) {
                throw ActiveMQMessageBundle.BUNDLE.addressHasBindings(address);
            }
        }
        managementService.unregisterAddress(address);
        final AddressInfo addressInfo = addressManager.removeAddressInfo(address);
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterRemoveAddress(address, addressInfo));
        }
        return addressInfo;
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 2 with Bindings

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

the class PostOfficeImpl method redistribute.

/**
 * The redistribution can't process the route right away as we may be dealing with a large message which will need to be processed on a different thread
 */
@Override
public Pair<RoutingContext, Message> redistribute(final Message message, final Queue originatingQueue, final Transaction tx) throws Exception {
    // We have to copy the message and store it separately, otherwise we may lose remote bindings in case of restart before the message
    // arrived the target node
    // as described on https://issues.jboss.org/browse/JBPAPP-6130
    Message copyRedistribute = message.copy(storageManager.generateID());
    Bindings bindings = addressManager.getBindingsForRoutingAddress(originatingQueue.getAddress());
    if (bindings != null) {
        RoutingContext context = new RoutingContextImpl(tx);
        boolean routed = bindings.redistribute(copyRedistribute, originatingQueue, context);
        if (routed) {
            return new Pair<>(context, copyRedistribute);
        }
    }
    return null;
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Pair(org.apache.activemq.artemis.api.core.Pair)

Example 3 with Bindings

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

the class PostOfficeImpl method route.

@Override
public RoutingStatus route(final Message message, final RoutingContext context, final boolean direct, boolean rejectDuplicates, final Binding bindingMove) throws Exception {
    RoutingStatus result;
    // Sanity check
    if (message.getRefCount() > 0) {
        throw new IllegalStateException("Message cannot be routed more than once");
    }
    setPagingStore(context.getAddress(message), message);
    AtomicBoolean startedTX = new AtomicBoolean(false);
    final SimpleString address = context.getAddress(message);
    applyExpiryDelay(message, address);
    if (!checkDuplicateID(message, context, rejectDuplicates, startedTX)) {
        return RoutingStatus.DUPLICATED_ID;
    }
    message.cleanupInternalProperties();
    Bindings bindings = addressManager.getBindingsForRoutingAddress(context.getAddress(message));
    // first check for the auto-queue creation thing
    if (bindings == null) {
    // There is no queue with this address, we will check if it needs to be created
    // if (queueCreator.create(address)) {
    // TODO: this is not working!!!!
    // reassign bindings if it was created
    // bindings = addressManager.getBindingsForRoutingAddress(address);
    // }
    }
    if (bindingMove != null) {
        bindingMove.route(message, context);
    } else if (bindings != null) {
        bindings.route(message, context);
    } else {
        // this is a debug and not warn because this could be a regular scenario on publish-subscribe queues (or topic subscriptions on JMS)
        if (logger.isDebugEnabled()) {
            logger.debug("Couldn't find any bindings for address=" + address + " on message=" + message);
        }
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeMessageRoute(message, context, direct, rejectDuplicates));
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Message after routed=" + message);
    }
    if (context.getQueueCount() == 0) {
        // Send to DLA if appropriate
        AddressSettings addressSettings = addressSettingsRepository.getMatch(address.toString());
        boolean sendToDLA = addressSettings.isSendToDLAOnNoRoute();
        if (sendToDLA) {
            // Send to the DLA for the address
            SimpleString dlaAddress = addressSettings.getDeadLetterAddress();
            if (logger.isDebugEnabled()) {
                logger.debug("sending message to dla address = " + dlaAddress + ", message=" + message);
            }
            if (dlaAddress == null) {
                result = RoutingStatus.NO_BINDINGS;
                ActiveMQServerLogger.LOGGER.noDLA(address);
            } else {
                message.referenceOriginalMessage(message, null);
                message.setAddress(dlaAddress);
                message.reencode();
                route(message, context.getTransaction(), false);
                result = RoutingStatus.NO_BINDINGS_DLA;
            }
        } else {
            result = RoutingStatus.NO_BINDINGS;
            if (logger.isDebugEnabled()) {
                logger.debug("Message " + message + " is not going anywhere as it didn't have a binding on address:" + address);
            }
            if (message.isLargeMessage()) {
                ((LargeServerMessage) message).deleteFile();
            }
        }
    } else {
        result = RoutingStatus.OK;
        try {
            processRoute(message, context, direct);
        } catch (ActiveMQAddressFullException e) {
            if (startedTX.get()) {
                context.getTransaction().rollback();
            } else if (context.getTransaction() != null) {
                context.getTransaction().markAsRollbackOnly(e);
            }
            throw e;
        }
    }
    if (startedTX.get()) {
        context.getTransaction().commit();
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterMessageRoute(message, context, direct, rejectDuplicates, result));
    }
    return result;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQAddressFullException(org.apache.activemq.artemis.api.core.ActiveMQAddressFullException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingStatus(org.apache.activemq.artemis.core.postoffice.RoutingStatus) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 4 with Bindings

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

the class WildcardAddressManager method removeAndUpdateAddressMap.

private synchronized void removeAndUpdateAddressMap(final Address address) throws Exception {
    // we only remove if there are no bindings left
    Bindings bindings = super.getBindingsForRoutingAddress(address.getAddress());
    if (bindings == null || bindings.getBindings().size() == 0) {
        List<Address> addresses = address.getLinkedAddresses();
        for (Address address1 : addresses) {
            address1.removeLinkedAddress(address);
            Bindings linkedBindings = super.getBindingsForRoutingAddress(address1.getAddress());
            if (linkedBindings == null || linkedBindings.getBindings().size() == 0) {
                removeAddress(address1);
            }
        }
        removeAddress(address);
    }
}
Also used : Address(org.apache.activemq.artemis.core.postoffice.Address) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 5 with Bindings

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

the class WildcardAddressManager method updateMessageLoadBalancingTypeForAddress.

@Override
public void updateMessageLoadBalancingTypeForAddress(SimpleString address, MessageLoadBalancingType messageLoadBalancingType) throws Exception {
    Address add = addAndUpdateAddressMap(address);
    Bindings bindingsForRoutingAddress = super.getBindingsForRoutingAddress(address);
    if (bindingsForRoutingAddress != null) {
        bindingsForRoutingAddress.setMessageLoadBalancingType(messageLoadBalancingType);
    }
    if (add.containsWildCard()) {
        for (Address destAdd : add.getLinkedAddresses()) {
            getBindingsForRoutingAddress(destAdd.getAddress()).setMessageLoadBalancingType(messageLoadBalancingType);
        }
    } else {
        for (Address destAdd : add.getLinkedAddresses()) {
            super.getBindingsForRoutingAddress(destAdd.getAddress()).setMessageLoadBalancingType(messageLoadBalancingType);
        }
    }
}
Also used : Address(org.apache.activemq.artemis.core.postoffice.Address) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

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