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;
}
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);
}
}
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;
}
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);
}
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;
}
Aggregations