use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class MessageGroupingConnectionFactoryTest method doTestBasicGroupingUsingConnectionFactory.
private void doTestBasicGroupingUsingConnectionFactory() throws Exception {
ClientProducer clientProducer = clientSession.createProducer(qName);
ClientConsumer consumer = clientSession.createConsumer(qName);
ClientConsumer consumer2 = clientSession.createConsumer(qName);
clientSession.start();
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(clientSession, "m" + i);
clientProducer.send(message);
}
CountDownLatch latch = new CountDownLatch(numMessages);
DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
consumer.setMessageHandler(dummyMessageHandler);
DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
consumer2.setMessageHandler(dummyMessageHandler2);
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
Assert.assertEquals(100, dummyMessageHandler.list.size());
Assert.assertEquals(0, dummyMessageHandler2.list.size());
consumer.close();
consumer2.close();
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class MessageCounterTest method testMessageCounter.
@Test
public void testMessageCounter() throws Exception {
locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(null, null, false, false, false, false, 0);
session.createQueue(QUEUE, QUEUE, null, false);
ClientProducer producer = session.createProducer(QUEUE);
final int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(session, "m" + i);
producer.send(message);
}
session.commit();
session.start();
Assert.assertEquals(100, getMessageCount(server.getPostOffice(), QUEUE.toString()));
ClientConsumer consumer = session.createConsumer(QUEUE, null, false);
for (int i = 0; i < numMessages; i++) {
ClientMessage message = consumer.receive(1000);
Assert.assertNotNull(message);
message.acknowledge();
session.commit();
Assert.assertEquals("m" + i, message.getBodyBuffer().readString());
}
session.close();
Assert.assertEquals(0, getMessageCount(server.getPostOffice(), QUEUE.toString()));
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class MessageExpirationTest method testMessageExpiredWithExpiryAddress.
@Test
public void testMessageExpiredWithExpiryAddress() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
final SimpleString expiryAddress = RandomUtil.randomSimpleString();
SimpleString expiryQueue = RandomUtil.randomSimpleString();
server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() {
private static final long serialVersionUID = -6476053400596299130L;
@Override
public SimpleString getExpiryAddress() {
return expiryAddress;
}
});
session.createQueue(address, queue, false);
session.createQueue(expiryAddress, expiryQueue, false);
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(false);
message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
producer.send(message);
Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
session.start();
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
ClientConsumer expiryConsumer = session.createConsumer(expiryQueue);
ClientMessage expiredMessage = expiryConsumer.receive(500);
Assert.assertNotNull(expiredMessage);
Assert.assertNotNull(expiredMessage.getObjectProperty(Message.HDR_ACTUAL_EXPIRY_TIME));
Assert.assertEquals(address, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_ADDRESS));
Assert.assertEquals(queue, expiredMessage.getObjectProperty(Message.HDR_ORIGINAL_QUEUE));
consumer.close();
expiryConsumer.close();
session.deleteQueue(queue);
session.deleteQueue(expiryQueue);
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class MessageExpirationTest method testMessageExpiredWithoutExpiryAddress.
@Test
public void testMessageExpiredWithoutExpiryAddress() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, queue, false);
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(false);
message.setExpiration(System.currentTimeMillis() + MessageExpirationTest.EXPIRATION);
producer.send(message);
Thread.sleep(MessageExpirationTest.EXPIRATION * 2);
session.start();
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
consumer.close();
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.client.ClientConsumer in project activemq-artemis by apache.
the class MessageGroupingTest method dotestMultipleGroupingXACommit.
private void dotestMultipleGroupingXACommit() throws Exception {
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sessionFactory = createSessionFactory(locator);
ClientSession clientSession = sessionFactory.createSession(true, false, false);
ClientProducer clientProducer = this.clientSession.createProducer(qName);
ClientConsumer consumer = clientSession.createConsumer(qName);
ClientConsumer consumer2 = clientSession.createConsumer(qName);
clientSession.start();
Xid xid = new XidImpl("bq".getBytes(), 4, "gtid".getBytes());
clientSession.start(xid, XAResource.TMNOFLAGS);
SimpleString groupId = new SimpleString("grp1");
SimpleString groupId2 = new SimpleString("grp2");
int numMessages = 100;
for (int i = 0; i < numMessages; i++) {
ClientMessage message = createTextMessage(clientSession, "m" + i);
if (i % 2 == 0 || i == 0) {
message.putStringProperty(Message.HDR_GROUP_ID, groupId);
} else {
message.putStringProperty(Message.HDR_GROUP_ID, groupId2);
}
clientProducer.send(message);
}
CountDownLatch latch = new CountDownLatch(numMessages);
DummyMessageHandler dummyMessageHandler = new DummyMessageHandler(latch, true);
consumer.setMessageHandler(dummyMessageHandler);
DummyMessageHandler dummyMessageHandler2 = new DummyMessageHandler(latch, true);
consumer2.setMessageHandler(dummyMessageHandler2);
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
clientSession.commit(xid, false);
Assert.assertEquals(dummyMessageHandler.list.size(), 50);
int i = 0;
for (ClientMessage message : dummyMessageHandler.list) {
Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
i += 2;
}
Assert.assertEquals(dummyMessageHandler2.list.size(), 50);
i = 1;
for (ClientMessage message : dummyMessageHandler2.list) {
Assert.assertEquals(message.getBodyBuffer().readString(), "m" + i);
i += 2;
}
consumer.close();
consumer2.close();
consumer = this.clientSession.createConsumer(qName);
Assert.assertNull(consumer.receiveImmediate());
clientSession.close();
locator.close();
}
Aggregations