Search in sources :

Example 66 with Message

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();
    }
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) HashMap(java.util.HashMap) Map(java.util.Map)

Example 67 with Message

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();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 68 with Message

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();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 69 with Message

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) {
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 70 with Message

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) {
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Aggregations

Message (org.apache.activemq.artemis.api.core.Message)114 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)56 Test (org.junit.Test)52 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)51 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)48 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)46 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)41 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)34 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)28 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)18 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)16 ArrayList (java.util.ArrayList)15 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)12 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)11 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)10 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)10 HashMap (java.util.HashMap)9 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)8