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);
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations