Search in sources :

Example 81 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.

the class ProducerFlowControlTest method testMultipleConsumers.

// Not technically a flow control test, but what the hell
@Test
public void testMultipleConsumers() throws Exception {
    server = createServer(false, isNetty());
    server.start();
    waitForServerToStart(server);
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true, true);
    session.createQueue("address", "queue1", null, false);
    session.createQueue("address", "queue2", null, false);
    session.createQueue("address", "queue3", null, false);
    session.createQueue("address", "queue4", null, false);
    session.createQueue("address", "queue5", null, false);
    ClientConsumer consumer1 = session.createConsumer("queue1");
    ClientConsumer consumer2 = session.createConsumer("queue2");
    ClientConsumer consumer3 = session.createConsumer("queue3");
    ClientConsumer consumer4 = session.createConsumer("queue4");
    ClientConsumer consumer5 = session.createConsumer("queue5");
    ClientProducer producer = session.createProducer("address");
    byte[] bytes = new byte[2000];
    ClientMessage message = session.createMessage(false);
    message.getBodyBuffer().writeBytes(bytes);
    final int numMessages = 1000;
    for (int i = 0; i < numMessages; i++) {
        producer.send(message);
    }
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage msg = consumer1.receive(1000);
        Assert.assertNotNull(msg);
        msg = consumer2.receive(5000);
        Assert.assertNotNull(msg);
        msg = consumer3.receive(5000);
        Assert.assertNotNull(msg);
        msg = consumer4.receive(5000);
        Assert.assertNotNull(msg);
        msg = consumer5.receive(5000);
        Assert.assertNotNull(msg);
    }
}
Also used : ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 82 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.

the class AutogroupIdTest method testGroupIdAutomaticallyNotSet.

/*
   * tests that even though we have a grouping round robin distributor we don't pin the consumer as autogroup is false
   * */
@Test
public void testGroupIdAutomaticallyNotSet() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(groupTestQ, groupTestQ, null, false);
    ClientProducer producer = session.createProducer(groupTestQ);
    final CountDownLatch latch = new CountDownLatch(100);
    MyMessageHandler myMessageHandler = new MyMessageHandler(latch);
    MyMessageHandler myMessageHandler2 = new MyMessageHandler(latch);
    ClientConsumer consumer = session.createConsumer(groupTestQ);
    consumer.setMessageHandler(myMessageHandler);
    ClientConsumer consumer2 = session.createConsumer(groupTestQ);
    consumer2.setMessageHandler(myMessageHandler2);
    session.start();
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        producer.send(session.createMessage(false));
    }
    waitForLatch(latch);
    session.close();
    Assert.assertEquals(50, myMessageHandler.messagesReceived);
    Assert.assertEquals(50, myMessageHandler2.messagesReceived);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 83 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.

the class CommitRollbackTest method testAsyncConsumerRollback.

@Test
public void testAsyncConsumerRollback() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setBlockOnAcknowledge(true).setAckBatchSize(0);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    final ClientSession session = cf.createSession(false, true, false);
    sendSession.createQueue(addressA, queueA, false);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientConsumer cc = session.createConsumer(queueA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(sendSession.createMessage(false));
    }
    CountDownLatch latch = new CountDownLatch(numMessages);
    session.start();
    cc.setMessageHandler(new ackHandler(session, latch));
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(numMessages, q.getDeliveringCount());
    Assert.assertEquals(numMessages, getMessageCount(q));
    session.stop();
    session.rollback();
    Assert.assertEquals(0, q.getDeliveringCount());
    Assert.assertEquals(numMessages, getMessageCount(q));
    latch = new CountDownLatch(numMessages);
    cc.setMessageHandler(new ackHandler(session, latch));
    session.start();
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    sendSession.close();
    session.close();
    cf.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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 84 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.

the class CommitRollbackTest method testReceiveWithCommit.

@Test
public void testReceiveWithCommit() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession(false, false, false);
    sendSession.createQueue(addressA, queueA, false);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientConsumer cc = session.createConsumer(queueA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(sendSession.createMessage(false));
    }
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage cm = cc.receive(5000);
        Assert.assertNotNull(cm);
        cm.acknowledge();
    }
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(numMessages, q.getDeliveringCount());
    session.commit();
    Assert.assertEquals(0, q.getDeliveringCount());
    session.close();
    sendSession.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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 85 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.

the class CommitRollbackTest method testReceiveWithRollback.

@Test
public void testReceiveWithRollback() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    ClientSession session = cf.createSession(false, false, false);
    sendSession.createQueue(addressA, queueA, false);
    ClientProducer cp = sendSession.createProducer(addressA);
    ClientConsumer cc = session.createConsumer(queueA);
    int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        cp.send(sendSession.createMessage(false));
    }
    session.start();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage cm = cc.receive(5000);
        Assert.assertNotNull(cm);
        cm.acknowledge();
    }
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    Assert.assertEquals(numMessages, q.getDeliveringCount());
    session.rollback();
    for (int i = 0; i < numMessages; i++) {
        ClientMessage cm = cc.receive(5000);
        Assert.assertNotNull(cm);
        cm.acknowledge();
    }
    Assert.assertEquals(numMessages, q.getDeliveringCount());
    session.close();
    sendSession.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) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Aggregations

ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)720 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)642 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)624 Test (org.junit.Test)584 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)569 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)409 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)348 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)154 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)132 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)88 Configuration (org.apache.activemq.artemis.core.config.Configuration)81 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)79 CountDownLatch (java.util.concurrent.CountDownLatch)72 Queue (org.apache.activemq.artemis.core.server.Queue)63 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)62 Xid (javax.transaction.xa.Xid)55 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)52 HashMap (java.util.HashMap)48 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)46 ArrayList (java.util.ArrayList)44