use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class ActiveMQServerTestCase method assertRemainingMessages.
protected boolean assertRemainingMessages(final int expected) throws Exception {
String queueName = "Queue1";
Binding binding = servers.get(0).getActiveMQServer().getPostOffice().getBinding(SimpleString.toSimpleString(queueName));
if (binding != null && binding instanceof LocalQueueBinding) {
((LocalQueueBinding) binding).getQueue().flushExecutor();
}
Long messageCount = null;
for (int i = 0; i < 10; i++) {
messageCount = servers.get(0).getMessageCountForQueue(queueName);
if (messageCount.longValue() == expected) {
break;
} else {
Thread.sleep(100);
}
}
ProxyAssertSupport.assertEquals(expected, messageCount.intValue());
return expected == messageCount.intValue();
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class ScaleDownTest method testStoreAndForward.
@Test
public void testStoreAndForward() throws Exception {
final int TEST_SIZE = 50;
final String addressName1 = "testAddress1";
final String addressName2 = "testAddress2";
final String queueName1 = "testQueue1";
final String queueName2 = "testQueue2";
// create queues on each node mapped to 2 addresses
createQueue(0, addressName1, queueName1, null, false);
createQueue(1, addressName1, queueName1, null, false);
createQueue(0, addressName2, queueName2, null, false);
createQueue(1, addressName2, queueName2, null, false);
// find and pause the sf queue so no messages actually move from node 0 to node 1
String sfQueueName = null;
for (Map.Entry<SimpleString, Binding> entry : servers[0].getPostOffice().getAllBindings().entrySet()) {
String temp = entry.getValue().getAddress().toString();
if (temp.startsWith(servers[1].getInternalNamingPrefix() + "sf.") && temp.endsWith(servers[1].getNodeID().toString())) {
// we found the sf queue for the other node
// need to pause the sfQueue here
((LocalQueueBinding) entry.getValue()).getQueue().pause();
sfQueueName = temp;
}
}
assertNotNull(sfQueueName);
// send messages to node 0
send(0, addressName1, TEST_SIZE, false, null);
send(0, addressName2, TEST_SIZE, false, null);
// add consumers to node 1 to force messages messages to redistribute to node 2 through the paused sf queue
addConsumer(0, 1, queueName1, null);
addConsumer(1, 1, queueName2, null);
LocalQueueBinding queue1Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName1)));
LocalQueueBinding queue2Binding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(queueName2)));
LocalQueueBinding sfQueueBinding = ((LocalQueueBinding) servers[0].getPostOffice().getBinding(new SimpleString(sfQueueName)));
long timeout = 5000;
long start = System.currentTimeMillis();
while (getMessageCount(queue1Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
start = System.currentTimeMillis();
while (getMessageCount(queue2Binding.getQueue()) > 0 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
start = System.currentTimeMillis();
while (getMessageCount(sfQueueBinding.getQueue()) < TEST_SIZE * 2 && System.currentTimeMillis() - start <= timeout) {
Thread.sleep(50);
}
// at this point on node 0 there should be 0 messages in test queues and TEST_SIZE * 2 messages in the sf queue
Assert.assertEquals(0, getMessageCount(queue1Binding.getQueue()));
Assert.assertEquals(0, getMessageCount(queue2Binding.getQueue()));
Assert.assertEquals(TEST_SIZE * 2, getMessageCount(sfQueueBinding.getQueue()));
removeConsumer(0);
removeConsumer(1);
// trigger scaleDown from node 0 to node 1
servers[0].stop();
// get the messages from node 1
addConsumer(0, 1, queueName1, null);
for (int i = 0; i < TEST_SIZE; i++) {
ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
}
ClientMessage clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
addConsumer(0, 1, queueName2, null);
for (int i = 0; i < TEST_SIZE; i++) {
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNotNull(clientMessage);
clientMessage.acknowledge();
}
clientMessage = consumers[0].getConsumer().receive(250);
Assert.assertNull(clientMessage);
removeConsumer(0);
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class JMSServerManagerImpl method destroyTopic.
@Override
public synchronized boolean destroyTopic(final String name, final boolean removeConsumers) throws Exception {
checkInitialised();
AddressControl addressControl = (AddressControl) server.getManagementService().getResource(ResourceNames.ADDRESS + name);
if (addressControl != null) {
for (String queueName : addressControl.getQueueNames()) {
Binding binding = server.getPostOffice().getBinding(new SimpleString(queueName));
if (binding == null) {
ActiveMQJMSServerLogger.LOGGER.noQueueOnTopic(queueName, name);
continue;
}
// We can't remove the remote binding. As this would be the bridge associated with the topic on this case
if (binding.getType() != BindingType.REMOTE_QUEUE) {
server.destroyQueue(SimpleString.toSimpleString(queueName), null, !removeConsumers, removeConsumers, true);
}
}
if (addressControl.getQueueNames().length == 0) {
try {
server.removeAddressInfo(SimpleString.toSimpleString(name), null);
} catch (ActiveMQAddressDoesNotExistException e) {
// ignore
}
removeFromBindings(topics, topicBindings, name);
topics.remove(name);
topicBindings.remove(name);
storage.deleteDestination(PersistedType.Topic, name);
sendNotification(JMSNotificationType.TOPIC_DESTROYED, name);
return true;
} else {
return false;
}
} else {
return false;
}
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class QueueImpl method moveBetweenSnFQueues.
@SuppressWarnings({ "ArrayToString", "ArrayToStringConcatenation" })
private void moveBetweenSnFQueues(final SimpleString queueSuffix, final Transaction tx, final MessageReference ref) throws Exception {
Message copyMessage = makeCopy(ref, false, false);
byte[] oldRouteToIDs = null;
String targetNodeID;
Binding targetBinding;
// remove the old route
for (SimpleString propName : copyMessage.getPropertyNames()) {
if (propName.startsWith(Message.HDR_ROUTE_TO_IDS)) {
oldRouteToIDs = (byte[]) copyMessage.removeProperty(propName.toString());
// don't use Arrays.toString(..) here
final String hashcodeToString = oldRouteToIDs.toString();
logger.debug("Removed property from message: " + propName + " = " + hashcodeToString + " (" + ByteBuffer.wrap(oldRouteToIDs).getLong() + ")");
// there should only be one of these properties so potentially save some loop iterations
break;
}
}
ByteBuffer oldBuffer = ByteBuffer.wrap(oldRouteToIDs);
RoutingContext routingContext = new RoutingContextImpl(tx);
/* this algorithm will look at the old route and find the new remote queue bindings where the messages should go
* and route them there directly
*/
while (oldBuffer.hasRemaining()) {
long oldQueueID = oldBuffer.getLong();
// look at all the bindings
Pair<String, Binding> result = locateTargetBinding(queueSuffix, copyMessage, oldQueueID);
targetBinding = result.getB();
targetNodeID = result.getA();
if (targetBinding == null) {
ActiveMQServerLogger.LOGGER.unableToFindTargetQueue(targetNodeID);
} else {
logger.debug("Routing on binding: " + targetBinding);
targetBinding.route(copyMessage, routingContext);
}
}
postOffice.processRoute(copyMessage, routingContext, false);
ref.handled();
acknowledge(tx, ref);
storageManager.afterCompleteOperations(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
ActiveMQServerLogger.LOGGER.ioErrorRedistributing(errorCode, errorMessage);
}
@Override
public void done() {
deliverAsync();
}
});
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class ServerSessionImpl method deleteQueue.
@Override
public void deleteQueue(final SimpleString queueToDelete) throws Exception {
final SimpleString unPrefixedQueueName = removePrefix(queueToDelete);
Binding binding = postOffice.getBinding(unPrefixedQueueName);
if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
throw new ActiveMQNonExistentQueueException();
}
server.destroyQueue(unPrefixedQueueName, this, true);
TempQueueCleanerUpper cleaner = this.tempQueueCleannerUppers.remove(unPrefixedQueueName);
if (cleaner != null) {
remotingConnection.removeCloseListener(cleaner);
remotingConnection.removeFailureListener(cleaner);
}
}
Aggregations