Search in sources :

Example 1 with RoutingContext

use of org.apache.activemq.artemis.core.server.RoutingContext 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 2 with RoutingContext

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

the class PostOfficeImpl method routeQueueInfo.

private void routeQueueInfo(final Message message, final Queue queue, final boolean applyFilters) throws Exception {
    if (!applyFilters || queue.getFilter() == null || queue.getFilter().match(message)) {
        RoutingContext context = new RoutingContextImpl(null);
        queue.route(message, context);
        processRoute(message, context, false);
    }
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext)

Example 3 with RoutingContext

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

the class Redistributor method handle.

@Override
public synchronized HandleStatus handle(final MessageReference reference) throws Exception {
    if (!active) {
        return HandleStatus.BUSY;
    } else if (reference.getMessage().getGroupID() != null) {
        // we shouldn't redistribute with message groups return NO_MATCH so other messages can be delivered
        return HandleStatus.NO_MATCH;
    }
    final Transaction tx = new TransactionImpl(storageManager);
    final Pair<RoutingContext, Message> routingInfo = postOffice.redistribute(reference.getMessage(), queue, tx);
    if (routingInfo == null) {
        return HandleStatus.BUSY;
    }
    if (!reference.getMessage().isLargeMessage()) {
        postOffice.processRoute(routingInfo.getB(), routingInfo.getA(), false);
        ackRedistribution(reference, tx);
    } else {
        active = false;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    postOffice.processRoute(routingInfo.getB(), routingInfo.getA(), false);
                    ackRedistribution(reference, tx);
                    synchronized (Redistributor.this) {
                        active = true;
                        count++;
                        queue.deliverAsync();
                    }
                } catch (Exception e) {
                    try {
                        tx.rollback();
                    } catch (Exception e2) {
                        // Nothing much we can do now
                        ActiveMQServerLogger.LOGGER.failedToRollback(e2);
                    }
                }
            }
        });
    }
    return HandleStatus.HANDLED;
}
Also used : RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) Transaction(org.apache.activemq.artemis.core.transaction.Transaction) Message(org.apache.activemq.artemis.api.core.Message) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)

Example 4 with RoutingContext

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

the class MQTTRetainMessageManager method sendToQueue.

private void sendToQueue(Message message, Queue queue, Transaction tx) throws Exception {
    RoutingContext context = new RoutingContextImpl(tx);
    queue.route(message, context);
    session.getServer().getPostOffice().processRoute(message, context, false);
}
Also used : RoutingContextImpl(org.apache.activemq.artemis.core.server.impl.RoutingContextImpl) RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext)

Example 5 with RoutingContext

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

the class PageCursorStressTest method pgMessages.

/**
 * @param storage
 * @param pageStore
 * @param pgParameter
 * @param start
 * @param NUM_MESSAGES
 * @param messageSize
 * @throws Exception
 */
private Transaction pgMessages(StorageManager storage, PagingStoreImpl pageStore, long pgParameter, int start, final int NUM_MESSAGES, final int messageSize) throws Exception {
    TransactionImpl txImpl = new TransactionImpl(pgParameter, null, storage);
    RoutingContext ctx = generateCTX(txImpl);
    for (int i = start; i < start + NUM_MESSAGES; i++) {
        ActiveMQBuffer buffer = RandomUtil.randomBuffer(messageSize, i + 1L);
        Message msg = new CoreMessage(storage.generateID(), buffer.writerIndex());
        msg.getBodyBuffer().writeBytes(buffer, 0, buffer.writerIndex());
        msg.putIntProperty("key", i);
        pageStore.page(msg, ctx.getTransaction(), ctx.getContextListing(ADDRESS), lock);
    }
    return txImpl;
}
Also used : RoutingContext(org.apache.activemq.artemis.core.server.RoutingContext) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)8 Message (org.apache.activemq.artemis.api.core.Message)6 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 RoutingContextImpl (org.apache.activemq.artemis.core.server.impl.RoutingContextImpl)3 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)2 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)2 ByteBuffer (java.nio.ByteBuffer)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)1 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)1 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)1 PagedReference (org.apache.activemq.artemis.core.paging.cursor.PagedReference)1 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)1 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)1 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)1