use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method testDeleteOnDrop.
@Test
public void testDeleteOnDrop() throws Exception {
fillAddress();
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = addClientSession(sf.createSession(false, true, false));
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
// Send large message which should be dropped and deleted from the filesystem
producer.send(clientFile);
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method testIgnoreStreaming.
/**
* Receive messages but never reads them, leaving the buffer pending
*/
@Test
public void testIgnoreStreaming() throws Exception {
ClientSession session = null;
ActiveMQServer server = null;
final int SIZE = 10 * 1024;
final int NUMBER_OF_MESSAGES = 1;
server = createServer(true, isNetty(), storeType);
server.start();
locator.setMinLargeMessageSize(1024);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(null, null, false, true, true, false, 0);
session.createQueue(ADDRESS, ADDRESS, null, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = session.createMessage(true);
msg.setBodyInputStream(ActiveMQTestBase.createFakeLargeStream(SIZE));
msg.putIntProperty(new SimpleString("key"), i);
producer.send(msg);
log.debug("Sent msg " + i);
}
session.start();
log.debug("Sending");
producer.close();
log.debug("Waiting");
ClientConsumer consumer = session.createConsumer(ADDRESS);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
ClientMessage msg = consumer.receive(50000);
Assert.assertNotNull(msg);
Assert.assertEquals(i, msg.getObjectProperty(new SimpleString("key")));
msg.acknowledge();
}
consumer.close();
session.commit();
Assert.assertEquals(0, ((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable()).getDeliveringCount());
Assert.assertEquals(0, getMessageCount(((Queue) server.getPostOffice().getBinding(ADDRESS).getBindable())));
log.debug("Thread done");
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method testDLALargeMessage.
@Test
public void testDLALargeMessage() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ClientSession session = null;
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = addClientSession(sf.createSession(false, false, false));
session.createQueue(ADDRESS, ADDRESS, true);
session.createQueue(ADDRESS, ADDRESS.concat("-2"), true);
SimpleString ADDRESS_DLA = ADDRESS.concat("-dla");
AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(ADDRESS_DLA).setMaxDeliveryAttempts(1);
server.getAddressSettingsRepository().addMatch("*", addressSettings);
session.createQueue(ADDRESS_DLA, ADDRESS_DLA, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS_DLA);
ClientConsumer consumerRollback = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumerRollback.receive(1000);
Assert.assertNotNull(msg1);
msg1.acknowledge();
session.rollback();
consumerRollback.close();
msg1 = consumer.receive(10000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
session.close();
server.stop();
server = createServer(true, isNetty(), storeType);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(false, false, false);
session.start();
consumer = session.createConsumer(ADDRESS_DLA);
msg1 = consumer.receive(10000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
msg1.acknowledge();
session.commit();
if (storeType != StoreConfiguration.StoreType.DATABASE) {
validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), isCompressedTest ? 0 : 1);
}
consumer = session.createConsumer(ADDRESS.concat("-2"));
msg1 = consumer.receive(10000);
Assert.assertNotNull(msg1);
for (int i = 0; i < messageSize; i++) {
Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
}
msg1.acknowledge();
session.commit();
session.close();
if (storeType != StoreConfiguration.StoreType.DATABASE) {
validateNoFilesOnLargeDir();
}
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method testCloseConsumer.
@Test
public void testCloseConsumer() throws Exception {
final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
ClientSession session = null;
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = addClientSession(sf.createSession(false, false, false));
session.createTemporaryQueue(ADDRESS, ADDRESS);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
producer.send(clientFile);
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(ADDRESS);
ClientMessage msg1 = consumer.receive(1000);
msg1.acknowledge();
session.commit();
Assert.assertNotNull(msg1);
consumer.close();
try {
msg1.getBodyBuffer().readByte();
Assert.fail("Exception was expected");
} catch (final Exception ignored) {
// empty on purpose
}
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.client.ClientProducer in project activemq-artemis by apache.
the class LargeMessageTest method internalTestRollbackPartiallyConsumedBuffer.
private void internalTestRollbackPartiallyConsumedBuffer(final boolean redeliveryDelay) throws Exception {
final int messageSize = largeMessageSize;
final ClientSession session;
ActiveMQServer server = createServer(true, isNetty(), storeType);
AddressSettings settings = new AddressSettings();
if (redeliveryDelay) {
settings.setRedeliveryDelay(100);
if (locator.isCompressLargeMessage()) {
locator.setConsumerWindowSize(0);
}
}
settings.setMaxDeliveryAttempts(-1);
server.getAddressSettingsRepository().addMatch("#", settings);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
for (int i = 0; i < 20; i++) {
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
clientFile.putIntProperty("value", i);
producer.send(clientFile);
}
session.commit();
session.start();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicInteger errors = new AtomicInteger(0);
ClientConsumer consumer = session.createConsumer(ADDRESS);
consumer.setMessageHandler(new MessageHandler() {
int counter = 0;
@Override
public void onMessage(ClientMessage message) {
message.getBodyBuffer().readByte();
// System.out.println("message:" + message);
try {
if (counter++ < 20) {
Thread.sleep(100);
// System.out.println("Rollback");
message.acknowledge();
session.rollback();
} else {
message.acknowledge();
session.commit();
}
if (counter == 40) {
latch.countDown();
}
} catch (Exception e) {
latch.countDown();
e.printStackTrace();
errors.incrementAndGet();
}
}
});
assertTrue(latch.await(40, TimeUnit.SECONDS));
consumer.close();
session.close();
validateNoFilesOnLargeDir();
}
Aggregations