ARTEMIS-1026 don't route when purgeOnNoConsumers and consumers=0

This commit is contained in:
Justin Bertram 2017-03-09 12:49:16 -06:00 committed by Clebert Suconic
parent a41951a585
commit a052e2ca9a
2 changed files with 21 additions and 3 deletions

View File

@ -439,6 +439,9 @@ public class QueueImpl implements Queue {
@Override
public void route(final Message message, final RoutingContext context) throws Exception {
if (purgeOnNoConsumers && getConsumerCount() == 0) {
return;
}
context.addQueue(address, this);
}

View File

@ -227,13 +227,28 @@ public class AddressingTest extends ActiveMQTestBase {
SimpleString address = new SimpleString("test.address");
SimpleString queueName = SimpleString.toSimpleString(UUID.randomUUID().toString());
server.createQueue(address, RoutingType.ANYCAST, queueName, null, null, true, false, false, false, false, 1, true, true);
assertNotNull(server.locateQueue(queueName));
Queue queue = server.locateQueue(queueName);
assertNotNull(queue);
ClientSession session = sessionFactory.createSession();
ClientProducer producer = session.createProducer(address);
// there are no consumers so no messages should be routed to the queue
producer.send(session.createMessage(true));
session.createConsumer(queueName).close();
assertEquals(0, queue.getMessageCount());
ClientConsumer consumer = session.createConsumer(queueName);
// there is a consumer now so the message should be routed
producer.send(session.createMessage(true));
assertEquals(1, queue.getMessageCount());
consumer.close();
// the last consumer was closed so the queue should exist but be purged
assertNotNull(server.locateQueue(queueName));
assertEquals(0, server.locateQueue(queueName).getMessageCount());
assertEquals(0, queue.getMessageCount());
// there are no consumers so no messages should be routed to the queue
producer.send(session.createMessage(true));
assertEquals(0, queue.getMessageCount());
}
@Test