Search in sources :

Example 86 with ClientMessage

use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.

the class LargeMessageAvoidLargeMessagesTest method testMixedCompressionSendReceive.

@Test
public void testMixedCompressionSendReceive() throws Exception {
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createTemporaryQueue(ADDRESS, ADDRESS);
    ClientProducer producer = session.createProducer(ADDRESS);
    final int minLargeSize = locator.getMinLargeMessageSize();
    TestLargeMessageInputStream regularInput = new TestLargeMessageInputStream(minLargeSize);
    adjustLargeCompression(true, regularInput, 1024);
    TestLargeMessageInputStream largeInput = new TestLargeMessageInputStream(minLargeSize);
    largeInput.setSize(100 * minLargeSize);
    adjustLargeCompression(false, largeInput, 50 * minLargeSize);
    int num = 6;
    for (int i = 0; i < num; i++) {
        ClientMessage clientFile = session.createMessage(true);
        if (i % 2 == 0) {
            clientFile.setBodyInputStream(regularInput.clone());
        } else {
            clientFile.setBodyInputStream(largeInput.clone());
        }
        producer.send(clientFile);
    }
    session.commit();
    session.start();
    // half the messages are sent as large
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), num / 2);
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int j = 0; j < num; j++) {
        ClientMessage msg1 = consumer.receive(1000);
        Assert.assertNotNull(msg1);
        if (j % 2 == 0) {
            for (int i = 0; i < regularInput.getSize(); i++) {
                byte b = msg1.getBodyBuffer().readByte();
                Assert.assertEquals("incorrect char ", regularInput.getChar(i), b);
            }
        } else {
            for (int i = 0; i < largeInput.getSize(); i++) {
                byte b = msg1.getBodyBuffer().readByte();
                Assert.assertEquals("incorrect char ", largeInput.getChar(i), b);
            }
        }
        msg1.acknowledge();
    }
    session.commit();
    consumer.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) Test(org.junit.Test)

Example 87 with ClientMessage

use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.

the class LargeMessageTest method internalTestResendMessage.

public void internalTestResendMessage(final long messageSize) throws Exception {
    clearDataRecreateServerDirs();
    ClientSession session = null;
    try {
        ActiveMQServer server = createServer(true, isNetty(), storeType);
        server.start();
        ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
        session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS, ADDRESS, true);
        SimpleString ADDRESS2 = ADDRESS.concat("-2");
        session.createQueue(ADDRESS2, ADDRESS2, true);
        ClientProducer producer = session.createProducer(ADDRESS);
        ClientProducer producer2 = session.createProducer(ADDRESS2);
        Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
        producer.send(clientFile);
        session.commit();
        session.start();
        ClientConsumer consumer = session.createConsumer(ADDRESS);
        ClientConsumer consumer2 = session.createConsumer(ADDRESS2);
        ClientMessage msg1 = consumer.receive(10000);
        msg1.acknowledge();
        producer2.send(msg1);
        session.commit();
        ClientMessage msg2 = consumer2.receive(10000);
        Assert.assertNotNull(msg2);
        msg2.acknowledge();
        session.commit();
        Assert.assertEquals(messageSize, msg2.getBodySize());
        compareString(messageSize, msg2);
        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) 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)

Example 88 with ClientMessage

use of org.apache.activemq.artemis.api.core.client.ClientMessage 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");
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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 89 with ClientMessage

use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
    }
}
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 90 with ClientMessage

use of org.apache.activemq.artemis.api.core.client.ClientMessage 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();
}
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) Test(org.junit.Test)

Aggregations

ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)889 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)708 Test (org.junit.Test)647 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)623 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)606 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)445 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)363 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)167 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)140 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)102 CountDownLatch (java.util.concurrent.CountDownLatch)99 Configuration (org.apache.activemq.artemis.core.config.Configuration)87 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)85 Queue (org.apache.activemq.artemis.core.server.Queue)72 Xid (javax.transaction.xa.Xid)67 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)63 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)54 HashMap (java.util.HashMap)53 ArrayList (java.util.ArrayList)51 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)47