Search in sources :

Example 66 with Queue

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

the class SlowConsumerTest method testMultipleConsumersOneQueue.

/**
 * This test creates 3 consumers on one queue. A producer sends
 * messages at a rate of 2 messages per second. Each consumer
 * consumes messages at rate of 1 message per second. The slow
 * consumer threshold is 1 message per second.
 * Based on the above settings, slow consumer removal will not
 * be performed (2 < 3*1), so no consumer will be removed during the
 * test, and all messages will be received.
 */
@Test
public void testMultipleConsumersOneQueue() throws Exception {
    locator.setAckBatchSize(0);
    Queue queue = server.locateQueue(QUEUE);
    ClientSessionFactory sf1 = createSessionFactory(locator);
    ClientSessionFactory sf2 = createSessionFactory(locator);
    ClientSessionFactory sf3 = createSessionFactory(locator);
    ClientSessionFactory sf4 = createSessionFactory(locator);
    final int messages = 10 * threshold;
    FixedRateProducer producer = new FixedRateProducer(threshold * 2, sf1, QUEUE, messages);
    final Set<FixedRateConsumer> consumers = new ConcurrentHashSet<>();
    final Set<ClientMessage> receivedMessages = new ConcurrentHashSet<>();
    consumers.add(new FixedRateConsumer(threshold, receivedMessages, sf2, QUEUE, 1));
    consumers.add(new FixedRateConsumer(threshold, receivedMessages, sf3, QUEUE, 2));
    consumers.add(new FixedRateConsumer(threshold, receivedMessages, sf4, QUEUE, 3));
    try {
        producer.start();
        for (FixedRateConsumer consumer : consumers) {
            consumer.start();
        }
        producer.join(10000);
        assertTrue(TimeUtils.waitOnBoolean(true, 10000, () -> receivedMessages.size() == messages));
        Assert.assertEquals(3, queue.getConsumerCount());
    } finally {
        producer.stopRunning();
        Assert.assertFalse(producer.failed);
        for (FixedRateConsumer consumer : consumers) {
            consumer.stopRunning();
            Assert.assertFalse(consumer.failed);
        }
        logger.debug("***report messages received: " + receivedMessages.size());
        logger.debug("***consumers left: " + consumers.size());
    }
}
Also used : ConcurrentHashSet(org.apache.activemq.artemis.utils.collections.ConcurrentHashSet) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Example 67 with Queue

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

the class SessionCreateAndDeleteQueueTest method testTemporaryTrue.

@Test
public void testTemporaryTrue() throws Exception {
    ClientSession session = createSessionFactory(locator).createSession(false, true, true);
    session.createTemporaryQueue(address, queueName);
    Binding binding = server.getPostOffice().getBinding(queueName);
    Queue q = (Queue) binding.getBindable();
    Assert.assertTrue(q.isTemporary());
    session.close();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Queue(org.apache.activemq.artemis.core.server.Queue) LastValueQueue(org.apache.activemq.artemis.core.server.impl.LastValueQueue) Test(org.junit.Test)

Example 68 with Queue

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

the class SessionCreateAndDeleteQueueTest method testcreateWithFilter.

@Test
public void testcreateWithFilter() throws Exception {
    ClientSession session = createSessionFactory(locator).createSession(false, true, true);
    SimpleString filterString = new SimpleString("x=y");
    session.createQueue(address, queueName, filterString, false);
    Binding binding = server.getPostOffice().getBinding(queueName);
    Queue q = (Queue) binding.getBindable();
    Assert.assertEquals(q.getFilter().getFilterString(), filterString);
    session.close();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) LastValueQueue(org.apache.activemq.artemis.core.server.impl.LastValueQueue) Test(org.junit.Test)

Example 69 with Queue

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

the class SessionCreateAndDeleteQueueTest method testDurableFalse.

@Test
public void testDurableFalse() throws Exception {
    ClientSession session = createSessionFactory(locator).createSession(false, true, true);
    session.createQueue(address, queueName, false);
    Binding binding = server.getPostOffice().getBinding(queueName);
    Queue q = (Queue) binding.getBindable();
    Assert.assertFalse(q.isDurable());
    session.close();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Queue(org.apache.activemq.artemis.core.server.Queue) LastValueQueue(org.apache.activemq.artemis.core.server.impl.LastValueQueue) Test(org.junit.Test)

Example 70 with Queue

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

the class TransactionalSendTest method testSendWithCommit.

@Test
public void testSendWithCommit() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, false, false);
    session.createQueue(addressA, queueA, false);
    ClientProducer cp = session.createProducer(addressA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(0, getMessageCount(q));
    session.commit();
    Assert.assertEquals(getMessageCount(q), numMessages);
    // now send some more
    for (int i = 0; i < numMessages; i++) {
        cp.send(session.createMessage(false));
    }
    Assert.assertEquals(numMessages, getMessageCount(q));
    session.commit();
    Assert.assertEquals(numMessages * 2, getMessageCount(q));
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) Test(org.junit.Test)

Aggregations

Queue (org.apache.activemq.artemis.core.server.Queue)275 Test (org.junit.Test)193 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)128 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)89 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)85 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)75 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)70 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)70 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)70 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)64 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)59 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)56 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)49 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)47 Session (javax.jms.Session)36 Connection (javax.jms.Connection)32 Configuration (org.apache.activemq.artemis.core.config.Configuration)31 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)30 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)27 TextMessage (javax.jms.TextMessage)25