Search in sources :

Example 1 with ActiveMQAddressFullException

use of org.apache.activemq.artemis.api.core.ActiveMQAddressFullException 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)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ActiveMQAddressFullException (org.apache.activemq.artemis.api.core.ActiveMQAddressFullException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)1 RoutingStatus (org.apache.activemq.artemis.core.postoffice.RoutingStatus)1 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1