use of org.apache.activemq.artemis.core.client.impl.ClientConsumerInternal in project activemq-artemis by apache.
the class ConsumerTest method receive.
private void receive(boolean cancelOnce) throws Throwable {
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true, false);
ClientProducer producer = session.createProducer(QUEUE);
ClientMessage message = session.createMessage(Message.TEXT_TYPE, true, 0, System.currentTimeMillis(), (byte) 4);
message.getBodyBuffer().writeString("hi");
message.putStringProperty("hello", "elo");
producer.send(message);
session.commit();
session.close();
if (durable) {
server.stop();
server.start();
}
sf = createSessionFactory(locator);
session = sf.createSession(false, true, true, false);
ClientConsumer consumer = session.createConsumer(QUEUE);
session.start();
if (cancelOnce) {
final ClientConsumerInternal consumerInternal = (ClientConsumerInternal) consumer;
Wait.waitFor(() -> consumerInternal.getBufferSize() > 0);
consumer.close();
consumer = session.createConsumer(QUEUE);
}
ClientMessage message2 = consumer.receive(1000);
Assert.assertNotNull(message2);
System.out.println("Id::" + message2.getMessageID());
System.out.println("Received " + message2);
System.out.println("Clie:" + ByteUtil.bytesToHex(message2.getBuffer().array(), 4));
System.out.println("String::" + message2.getReadOnlyBodyBuffer().readString());
Assert.assertEquals("elo", message2.getStringProperty("hello"));
Assert.assertEquals("hi", message2.getReadOnlyBodyBuffer().readString());
Assert.assertNull(consumer.receiveImmediate());
session.close();
}
use of org.apache.activemq.artemis.core.client.impl.ClientConsumerInternal in project activemq-artemis by apache.
the class PagingTest method testMoveExpire.
@Test
public void testMoveExpire() throws Exception {
clearDataRecreateServerDirs();
Configuration config = // disable compact
createDefaultInVMConfig().setJournalDirectory(getJournalDir()).setJournalSyncNonTransactional(false).setJournalCompactMinFiles(0).setMessageExpiryScanPeriod(500);
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(PAGE_SIZE).setMaxSizeBytes(PAGE_MAX).setExpiryAddress(new SimpleString("EXP")).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
server.getAddressSettingsRepository().clear();
server.getAddressSettingsRepository().addMatch("#", defaultSetting);
server.start();
final int numberOfMessages = 5000;
locator = createInVMNonHALocator().setConsumerWindowSize(10 * 1024 * 1024).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
session.createQueue("EXP", "EXP", null, true);
Queue queue1 = server.locateQueue(ADDRESS);
Queue qEXP = server.locateQueue(new SimpleString("EXP"));
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
final int MESSAGE_SIZE = 1024;
byte[] body = new byte[MESSAGE_SIZE];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= MESSAGE_SIZE; j++) {
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++) {
ClientMessage message = session.createMessage(true);
if (i < 1000) {
message.setExpiration(System.currentTimeMillis() + 100);
}
message.putIntProperty("tst-count", i);
ActiveMQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
producer.send(message);
if (i % 1000 == 0) {
session.commit();
}
}
session.commit();
producer.close();
Wait.assertEquals(1000, qEXP::getMessageCount);
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int i = 0; i < numberOfMessages - 1000; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
message.acknowledge();
assertTrue(message.getIntProperty("tst-count") >= 1000);
}
session.commit();
assertNull(consumer.receiveImmediate());
Wait.assertEquals(0, queue1::getMessageCount);
consumer.close();
consumer = session.createConsumer("EXP");
for (int i = 0; i < 1000; i++) {
ClientMessage message = consumer.receive(5000);
assertNotNull(message);
message.acknowledge();
assertTrue(message.getIntProperty("tst-count") < 1000);
}
assertNull(consumer.receiveImmediate());
// This is just to hold some messages as being delivered
ClientConsumerInternal cons = (ClientConsumerInternal) session.createConsumer(ADDRESS);
session.commit();
producer.close();
session.close();
server.stop();
}
Aggregations