Search in sources :

Example 36 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings 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 37 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings 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();
}
Also used : 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) MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 38 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class LargeMessageTest method testPageOnLargeMessage.

protected void testPageOnLargeMessage(final boolean realFiles, final boolean sendBlocking) throws Exception {
    Configuration config = createDefaultConfig(isNetty());
    final int PAGE_MAX = 20 * 1024;
    final int PAGE_SIZE = 10 * 1024;
    HashMap<String, AddressSettings> map = new HashMap<>();
    AddressSettings value = new AddressSettings();
    map.put(ADDRESS.toString(), value);
    ActiveMQServer server = createServer(realFiles, config, PAGE_SIZE, PAGE_MAX, map, storeType);
    server.start();
    final int numberOfBytes = 1024;
    final int numberOfBytesBigMessage = 400000;
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    if (sendBlocking) {
        sf.getServerLocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    }
    ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
    session.createQueue(ADDRESS, ADDRESS, null, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    ClientMessage message = null;
    for (int i = 0; i < 100; i++) {
        message = session.createMessage(true);
        // TODO: Why do I need to reset the writerIndex?
        message.getBodyBuffer().writerIndex(0);
        for (int j = 1; j <= numberOfBytes; j++) {
            message.getBodyBuffer().writeInt(j);
        }
        producer.send(message);
    }
    ClientMessage clientFile = createLargeClientMessageStreaming(session, numberOfBytesBigMessage);
    producer.send(clientFile);
    session.close();
    if (realFiles) {
        server.stop();
        server = createServer(true, config, PAGE_SIZE, PAGE_MAX, map, storeType);
        server.start();
        sf = createSessionFactory(locator);
    }
    session = sf.createSession(null, null, false, true, true, false, 0);
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 100; i++) {
        ClientMessage message2 = consumer.receive(LargeMessageTest.RECEIVE_WAIT_TIME);
        Assert.assertNotNull(message2);
        message2.acknowledge();
        Assert.assertNotNull(message2);
        message.getBodyBuffer().readerIndex(0);
        for (int j = 1; j <= numberOfBytes; j++) {
            Assert.assertEquals(j, message.getBodyBuffer().readInt());
        }
    }
    consumer.close();
    session.close();
    session = sf.createSession(null, null, false, true, true, false, 0);
    readMessage(session, ADDRESS, numberOfBytesBigMessage);
    // printBuffer("message received : ", message2.getBody());
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) HashMap(java.util.HashMap) 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 39 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class LargeMessageTest method testDLAOnExpiryNonDurableMessage.

@Test
public void testDLAOnExpiryNonDurableMessage() 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));
    SimpleString ADDRESS_DLA = ADDRESS.concat("-dla");
    SimpleString ADDRESS_EXPIRY = ADDRESS.concat("-expiry");
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(ADDRESS_DLA).setExpiryAddress(ADDRESS_EXPIRY).setMaxDeliveryAttempts(1);
    server.getAddressSettingsRepository().addMatch("*", addressSettings);
    session = sf.createSession(false, false, false);
    session.createQueue(ADDRESS, ADDRESS, true);
    session.createQueue(ADDRESS_DLA, ADDRESS_DLA, true);
    session.createQueue(ADDRESS_EXPIRY, ADDRESS_EXPIRY, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, false);
    clientFile.setExpiration(System.currentTimeMillis());
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumerExpired = session.createConsumer(ADDRESS);
    // to kick expiry quicker than waiting reaper thread
    Assert.assertNull(consumerExpired.receiveImmediate());
    consumerExpired.close();
    ClientConsumer consumerExpiry = session.createConsumer(ADDRESS_EXPIRY);
    ClientMessage msg1 = consumerExpiry.receive(5000);
    assertTrue(msg1.isLargeMessage());
    Assert.assertNotNull(msg1);
    msg1.acknowledge();
    for (int j = 0; j < messageSize; j++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
    }
    session.rollback();
    consumerExpiry.close();
    for (int i = 0; i < 10; i++) {
        consumerExpiry = session.createConsumer(ADDRESS_DLA);
        msg1 = consumerExpiry.receive(5000);
        Assert.assertNotNull(msg1);
        msg1.acknowledge();
        for (int j = 0; j < messageSize; j++) {
            Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
        }
        session.rollback();
        consumerExpiry.close();
    }
    session.close();
    session = sf.createSession(false, false, false);
    session.start();
    consumerExpiry = session.createConsumer(ADDRESS_DLA);
    msg1 = consumerExpiry.receive(5000);
    Assert.assertNotNull(msg1);
    msg1.acknowledge();
    for (int i = 0; i < messageSize; i++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
    }
    session.commit();
    consumerExpiry.close();
    session.commit();
    session.close();
    server.stop();
    server.start();
    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 40 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class LargeMessageTest method testDLAOnExpiry.

@Test
public void testDLAOnExpiry() 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));
    SimpleString ADDRESS_DLA = ADDRESS.concat("-dla");
    SimpleString ADDRESS_EXPIRY = ADDRESS.concat("-expiry");
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(ADDRESS_DLA).setExpiryAddress(ADDRESS_EXPIRY).setMaxDeliveryAttempts(1);
    server.getAddressSettingsRepository().addMatch("*", addressSettings);
    session = sf.createSession(false, false, false);
    session.createQueue(ADDRESS, ADDRESS, true);
    session.createQueue(ADDRESS_DLA, ADDRESS_DLA, true);
    session.createQueue(ADDRESS_EXPIRY, ADDRESS_EXPIRY, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    clientFile.setExpiration(System.currentTimeMillis());
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumerExpired = session.createConsumer(ADDRESS);
    // to kick expiry quicker than waiting reaper thread
    Assert.assertNull(consumerExpired.receiveImmediate());
    consumerExpired.close();
    ClientConsumer consumerExpiry = session.createConsumer(ADDRESS_EXPIRY);
    ClientMessage msg1 = consumerExpiry.receive(5000);
    Assert.assertNotNull(msg1);
    msg1.acknowledge();
    for (int j = 0; j < messageSize; j++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
    }
    session.rollback();
    consumerExpiry.close();
    for (int i = 0; i < 10; i++) {
        consumerExpiry = session.createConsumer(ADDRESS_DLA);
        msg1 = consumerExpiry.receive(5000);
        Assert.assertNotNull(msg1);
        msg1.acknowledge();
        for (int j = 0; j < messageSize; j++) {
            Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), msg1.getBodyBuffer().readByte());
        }
        session.rollback();
        consumerExpiry.close();
    }
    session.close();
    server.stop();
    server = createServer(true, isNetty(), storeType);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false, false);
    session.start();
    consumerExpiry = session.createConsumer(ADDRESS_DLA);
    msg1 = consumerExpiry.receive(5000);
    Assert.assertNotNull(msg1);
    msg1.acknowledge();
    for (int i = 0; i < messageSize; i++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg1.getBodyBuffer().readByte());
    }
    session.commit();
    consumerExpiry.close();
    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)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14