Search in sources :

Example 6 with Consumer

use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.

the class QueueImplTest method testAddRemoveConsumer.

@Test
public void testAddRemoveConsumer() throws Exception {
    Consumer cons1 = new FakeConsumer();
    Consumer cons2 = new FakeConsumer();
    Consumer cons3 = new FakeConsumer();
    QueueImpl queue = getTemporaryQueue();
    Assert.assertEquals(0, queue.getConsumerCount());
    queue.addConsumer(cons1);
    Assert.assertEquals(1, queue.getConsumerCount());
    queue.removeConsumer(cons1);
    Assert.assertEquals(0, queue.getConsumerCount());
    queue.addConsumer(cons1);
    queue.addConsumer(cons2);
    queue.addConsumer(cons3);
    Assert.assertEquals(3, queue.getConsumerCount());
    queue.removeConsumer(new FakeConsumer());
    Assert.assertEquals(3, queue.getConsumerCount());
    queue.removeConsumer(cons1);
    Assert.assertEquals(2, queue.getConsumerCount());
    queue.removeConsumer(cons2);
    Assert.assertEquals(1, queue.getConsumerCount());
    queue.removeConsumer(cons3);
    Assert.assertEquals(0, queue.getConsumerCount());
    queue.removeConsumer(cons3);
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Consumer(org.apache.activemq.artemis.core.server.Consumer) FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 7 with Consumer

use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.

the class QueueImplTest method testDeliveryScheduled.

@Test
public void testDeliveryScheduled() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    Consumer consumer = new FakeConsumer() {

        @Override
        public synchronized HandleStatus handle(final MessageReference reference) {
            countDownLatch.countDown();
            return HandleStatus.HANDLED;
        }

        @Override
        public void disconnect() {
        }
    };
    QueueImpl queue = new QueueImpl(1, new SimpleString("address1"), QueueImplTest.queue1, null, null, false, true, false, scheduledExecutor, null, null, null, ArtemisExecutor.delegate(executor), null, null);
    MessageReference messageReference = generateReference(queue, 1);
    queue.addConsumer(consumer);
    messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 200);
    queue.addHead(messageReference, false);
    boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(gotLatch);
}
Also used : FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) Consumer(org.apache.activemq.artemis.core.server.Consumer) FakeConsumer(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CountDownLatch(java.util.concurrent.CountDownLatch) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) Test(org.junit.Test)

Example 8 with Consumer

use of org.apache.activemq.artemis.core.server.Consumer in project activemq-artemis by apache.

the class QueueImpl method hasMatchingConsumer.

@Override
public boolean hasMatchingConsumer(final Message message) {
    for (ConsumerHolder holder : consumerList) {
        Consumer consumer = holder.consumer;
        if (consumer instanceof Redistributor) {
            continue;
        }
        Filter filter1 = consumer.getFilter();
        if (filter1 == null) {
            return true;
        } else {
            if (filter1.match(message)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Consumer(org.apache.activemq.artemis.core.server.Consumer) Filter(org.apache.activemq.artemis.core.filter.Filter) Redistributor(org.apache.activemq.artemis.core.server.cluster.impl.Redistributor)

Aggregations

Consumer (org.apache.activemq.artemis.core.server.Consumer)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 Binding (org.apache.activemq.artemis.core.postoffice.Binding)2 HandleStatus (org.apache.activemq.artemis.core.server.HandleStatus)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2 ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)2 QueueImpl (org.apache.activemq.artemis.core.server.impl.QueueImpl)2 FakeConsumer (org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakeConsumer)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 NoSuchElementException (java.util.NoSuchElementException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 ActiveMQAddressDoesNotExistException (org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1