use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class QueueControlImpl method getFirstMessage.
protected Map<String, Object>[] getFirstMessage() throws Exception {
checkStarted();
clearIO();
try {
List<Map<String, Object>> messages = new ArrayList<>();
queue.flushExecutor();
try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
// returns just the first, as it's the first only
if (iterator.hasNext()) {
MessageReference ref = iterator.next();
Message message = ref.getMessage();
messages.add(message.toMap());
}
return messages.toArray(new Map[1]);
}
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageAvoidLargeMessagesTest method testDLALargeMessage.
// this test won't leave any large messages in the large-messages dir
// because after compression, the messages are regulars at server.
@Override
@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());
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());
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();
// large message becomes a regular at server.
validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 0);
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();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method testTwoBindings.
public void testTwoBindings(final boolean restart) throws Exception {
// there are two bindings.. one is ACKed, the other is not, the server is restarted
// The other binding is acked... The file must be deleted
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
SimpleString[] queue = new SimpleString[] { new SimpleString("queue1"), new SimpleString("queue2") };
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
session.createQueue(ADDRESS, queue[0], null, true);
session.createQueue(ADDRESS, queue[1], null, true);
int numberOfBytes = 400000;
Message clientFile = createLargeClientMessageStreaming(session, numberOfBytes);
ClientProducer producer = session.createProducer(ADDRESS);
producer.send(clientFile);
producer.close();
readMessage(session, queue[1], numberOfBytes);
if (restart) {
session.close();
server.stop();
server = createServer(true, isNetty(), storeType);
server.start();
sf = createSessionFactory(locator);
session = sf.createSession(null, null, false, true, true, false, 0);
}
readMessage(session, queue[0], numberOfBytes);
session.close();
validateNoFilesOnLargeDir();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method internalTestCachedResendMessage.
public void internalTestCachedResendMessage(final long messageSize) throws Exception {
ClientSession session = null;
try {
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
locator.setMinLargeMessageSize(200).setCacheLargeMessagesClient(true);
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message originalMsg = createLargeClientMessageStreaming(session, messageSize, false);
producer.send(originalMsg);
session.commit();
ClientConsumer consumer = session.createConsumer(ADDRESS);
session.start();
ClientMessage msgReceived = consumer.receive(10000);
msgReceived.acknowledge();
session.commit();
compareString(messageSize, msgReceived);
msgReceived.getBodyBuffer().readerIndex(0);
producer.send(msgReceived);
session.commit();
ClientMessage msgReceived2 = consumer.receive(10000);
msgReceived2.acknowledge();
compareString(messageSize, msgReceived2);
session.commit();
session.close();
validateNoFilesOnLargeDir();
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class LargeMessageTest method internalTestSentWithDuplicateID.
private void internalTestSentWithDuplicateID(final boolean isSimulateBridge) throws Exception {
final int messageSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
ClientSession session = null;
try {
ActiveMQServer server = createServer(true, isNetty(), storeType);
server.start();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
session = sf.createSession(true, true, 0);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
String someDuplicateInfo = "Anything";
for (int i = 0; i < 10; i++) {
Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
if (isSimulateBridge) {
clientFile.putBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, someDuplicateInfo.getBytes());
} else {
clientFile.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, someDuplicateInfo.getBytes());
}
producer.send(clientFile);
}
ClientConsumer consumer = session.createConsumer(ADDRESS);
session.start();
ClientMessage msg = consumer.receive(10000);
for (int i = 0; i < messageSize; i++) {
assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
}
assertNotNull(msg);
msg.acknowledge();
assertNull(consumer.receiveImmediate());
session.commit();
validateNoFilesOnLargeDir();
} finally {
try {
session.close();
} catch (Throwable ignored) {
}
}
}
Aggregations