use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.
the class BindingsImpl method route.
private void route(final Message message, final RoutingContext context, final boolean groupRouting) throws Exception {
/* This is a special treatment for scaled-down messages involving SnF queues.
* See org.apache.activemq.artemis.core.server.impl.ScaleDownHandler.scaleDownMessages() for the logic that sends messages with this property
*/
byte[] ids = (byte[]) message.removeExtraBytesProperty(Message.HDR_SCALEDOWN_TO_IDS);
if (ids != null) {
ByteBuffer buffer = ByteBuffer.wrap(ids);
while (buffer.hasRemaining()) {
long id = buffer.getLong();
for (Map.Entry<Long, Binding> entry : bindingsMap.entrySet()) {
if (entry.getValue() instanceof RemoteQueueBinding) {
RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) entry.getValue();
if (remoteQueueBinding.getRemoteQueueID() == id) {
message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, ByteBuffer.allocate(8).putLong(remoteQueueBinding.getID()).array());
}
}
}
}
}
boolean routed = false;
for (Binding binding : exclusiveBindings) {
if (binding.getFilter() == null || binding.getFilter().match(message)) {
binding.getBindable().route(message, context);
routed = true;
}
}
if (!routed) {
// Remove the ids now, in order to avoid double check
ids = message.removeExtraBytesProperty(Message.HDR_ROUTE_TO_IDS);
// Fetch the groupId now, in order to avoid double checking
SimpleString groupId = message.getGroupID();
if (ids != null) {
routeFromCluster(message, context, ids);
} else if (groupingHandler != null && groupRouting && groupId != null) {
routeUsingStrictOrdering(message, context, groupingHandler, groupId, 0);
} else {
if (logger.isTraceEnabled()) {
logger.trace("Routing message " + message + " on binding=" + this);
}
for (Map.Entry<SimpleString, List<Binding>> entry : routingNameBindingMap.entrySet()) {
SimpleString routingName = entry.getKey();
List<Binding> bindings = entry.getValue();
if (bindings == null) {
// ConcurrentHashMap behaviour!
continue;
}
Binding theBinding = getNextBinding(message, routingName, bindings);
if (theBinding != null) {
theBinding.route(message, context);
}
}
}
}
}
use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.
the class QueueImpl method locateTargetBinding.
private Pair<String, Binding> locateTargetBinding(SimpleString queueSuffix, Message copyMessage, long oldQueueID) {
String targetNodeID = null;
Binding targetBinding = null;
for (Map.Entry<SimpleString, Binding> entry : postOffice.getAllBindings().entrySet()) {
Binding binding = entry.getValue();
// we only care about the remote queue bindings
if (binding instanceof RemoteQueueBinding) {
RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) binding;
// does this remote queue binding point to the same queue as the message?
if (oldQueueID == remoteQueueBinding.getRemoteQueueID()) {
// get the name of this queue so we can find the corresponding remote queue binding pointing to the scale down target node
SimpleString oldQueueName = remoteQueueBinding.getRoutingName();
// parse the queue name of the remote queue binding to determine the node ID
String temp = remoteQueueBinding.getQueue().getName().toString();
targetNodeID = temp.substring(temp.lastIndexOf(".") + 1);
logger.debug("Message formerly destined for " + oldQueueName + " with ID: " + oldQueueID + " on address " + copyMessage.getAddressSimpleString() + " on node " + targetNodeID);
// now that we have the name of the queue we need to look through all the bindings again to find the new remote queue binding
for (Map.Entry<SimpleString, Binding> entry2 : postOffice.getAllBindings().entrySet()) {
binding = entry2.getValue();
// again, we only care about the remote queue bindings
if (binding instanceof RemoteQueueBinding) {
remoteQueueBinding = (RemoteQueueBinding) binding;
temp = remoteQueueBinding.getQueue().getName().toString();
targetNodeID = temp.substring(temp.lastIndexOf(".") + 1);
if (oldQueueName.equals(remoteQueueBinding.getRoutingName()) && targetNodeID.equals(queueSuffix.toString())) {
targetBinding = remoteQueueBinding;
if (logger.isDebugEnabled()) {
logger.debug("Message now destined for " + remoteQueueBinding.getRoutingName() + " with ID: " + remoteQueueBinding.getRemoteQueueID() + " on address " + copyMessage.getAddress() + " on node " + targetNodeID);
}
break;
} else {
logger.debug("Failed to match: " + remoteQueueBinding);
}
}
}
}
}
}
return new Pair<>(targetNodeID, targetBinding);
}
use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.
the class ClusterTestBase method waitForBindings.
protected void waitForBindings(final int node, final String address, final int expectedBindingCount, final int expectedConsumerCount, final boolean local) throws Exception {
log.debug("waiting for bindings on node " + node + " address " + address + " expectedBindingCount " + expectedBindingCount + " consumerCount " + expectedConsumerCount + " local " + local);
ActiveMQServer server = servers[node];
if (server == null) {
throw new IllegalArgumentException("No server at " + node);
}
long timeout = ActiveMQTestBase.WAIT_TIMEOUT;
if (waitForBindings(server, address, local, expectedBindingCount, expectedConsumerCount, timeout)) {
return;
}
PostOffice po = server.getPostOffice();
Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
System.out.println("=======================================================================");
System.out.println("Binding information for address = " + address + " on node " + node);
for (Binding binding : bindings.getBindings()) {
if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
QueueBinding qBinding = (QueueBinding) binding;
System.out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
}
}
StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
try {
for (ActiveMQServer activeMQServer : servers) {
if (activeMQServer != null) {
out.println(clusterDescription(activeMQServer));
out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
}
}
for (ActiveMQServer activeMQServer : servers) {
out.println("Management bindings on " + activeMQServer);
if (activeMQServer != null) {
out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
}
}
} catch (Throwable dontCare) {
}
logAndSystemOut(writer.toString());
throw new IllegalStateException("Didn't get the expected number of bindings, look at the logging for more information");
}
use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.
the class ActiveMQTestBase method waitForBindings.
/**
* @param server the server where's being checked
* @param address the name of the address being checked
* @param local if true we are looking for local bindings, false we are looking for remoting servers
* @param expectedBindingCount the expected number of counts
* @param expectedConsumerCount the expected number of consumers
* @param timeout the timeout used on the check
* @return
* @throws Exception
* @throws InterruptedException
*/
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
final PostOffice po = server.getPostOffice();
long start = System.currentTimeMillis();
int bindingCount = 0;
int totConsumers = 0;
do {
bindingCount = 0;
totConsumers = 0;
Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
for (Binding binding : bindings.getBindings()) {
if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
QueueBinding qBinding = (QueueBinding) binding;
bindingCount++;
totConsumers += qBinding.consumerCount();
}
}
if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
return true;
}
Thread.sleep(10);
} while (System.currentTimeMillis() - start < timeout);
String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
log.error(msg);
return false;
}
use of org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding in project activemq-artemis by apache.
the class MessageRedistributionTest method getRemoteQueueBinding.
private RemoteQueueBinding getRemoteQueueBinding(ActiveMQServer server) throws Exception {
ActiveMQServer remoteServer = server;
Bindings bindings = remoteServer.getPostOffice().getBindingsForAddress(new SimpleString("queues.testaddress"));
Collection<Binding> bindingSet = bindings.getBindings();
return getRemoteQueueBinding(bindingSet);
}
Aggregations