use of org.apache.activemq.artemis.core.postoffice.RoutingStatus 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;
}
use of org.apache.activemq.artemis.core.postoffice.RoutingStatus in project activemq-artemis by apache.
the class ServerSessionImpl method doSend.
@Override
public synchronized RoutingStatus doSend(final Transaction tx, final Message msg, final SimpleString originalAddress, final boolean direct, final boolean noAutoCreateQueue) throws Exception {
RoutingStatus result = RoutingStatus.OK;
RoutingType routingType = msg.getRoutingType();
/* TODO-now: How to address here with AMQP?
if (originalAddress != null) {
if (originalAddress.toString().startsWith("anycast:")) {
routingType = RoutingType.ANYCAST;
} else if (originalAddress.toString().startsWith("multicast:")) {
routingType = RoutingType.MULTICAST;
}
} */
AddressInfo art = getAddressAndRoutingType(new AddressInfo(msg.getAddressSimpleString(), routingType));
// check the user has write access to this address.
try {
securityCheck(art.getName(), CheckType.SEND, this);
} catch (ActiveMQException e) {
if (!autoCommitSends && tx != null) {
tx.markAsRollbackOnly(e);
}
throw e;
}
if (server.getConfiguration().isPopulateValidatedUser() && validatedUser != null) {
msg.setValidatedUserID(validatedUser);
}
if (tx == null || autoCommitSends) {
} else {
routingContext.setTransaction(tx);
}
try {
routingContext.setAddress(art.getName());
routingContext.setRoutingType(art.getRoutingType());
result = postOffice.route(msg, routingContext, direct);
Pair<Object, AtomicLong> value = targetAddressInfos.get(msg.getAddressSimpleString());
if (value == null) {
targetAddressInfos.put(msg.getAddressSimpleString(), new Pair<>(msg.getUserID(), new AtomicLong(1)));
} else {
value.setA(msg.getUserID());
value.getB().incrementAndGet();
}
} finally {
routingContext.clear();
}
return result;
}
use of org.apache.activemq.artemis.core.postoffice.RoutingStatus in project activemq-artemis by apache.
the class ServerSessionImpl method send.
@Override
public synchronized RoutingStatus send(Transaction tx, Message msg, final boolean direct, boolean noAutoCreateQueue) throws Exception {
final Message message;
if ((msg.getEncodeSize() > storageManager.getMaxRecordSize()) && !msg.isLargeMessage()) {
message = messageToLargeMessage(msg);
} else {
message = msg;
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeSend(this, tx, message, direct, noAutoCreateQueue));
}
// If the protocol doesn't support flow control, we have no choice other than fail the communication
if (!this.getRemotingConnection().isSupportsFlowControl() && pagingManager.isDiskFull()) {
ActiveMQIOErrorException exception = ActiveMQMessageBundle.BUNDLE.diskBeyondLimit();
this.getRemotingConnection().fail(exception);
throw exception;
}
final RoutingStatus result;
// case the id header already generated.
if (!message.isLargeMessage()) {
long id = storageManager.generateID();
// This will re-encode the message
message.setMessageID(id);
}
SimpleString address = message.getAddressSimpleString();
if (defaultAddress == null && address != null) {
defaultAddress = address;
}
if (address == null) {
// We don't want to force a re-encode when the message gets sent to the consumer
message.setAddress(defaultAddress);
}
if (logger.isTraceEnabled()) {
logger.trace("send(message=" + message + ", direct=" + direct + ") being called");
}
if (message.getAddress() == null) {
// This could happen with some tests that are ignoring messages
throw ActiveMQMessageBundle.BUNDLE.noAddress();
}
if (message.getAddressSimpleString().equals(managementAddress)) {
// It's a management message
result = handleManagementMessage(tx, message, direct);
} else {
result = doSend(tx, message, address, direct, noAutoCreateQueue);
}
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterSend(this, tx, message, direct, noAutoCreateQueue, result));
}
return result;
}
Aggregations