Search in sources :

Example 71 with Message

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

the class LargeMessageTest method testExpiryLargeMessage.

@Test
public void testExpiryLargeMessage() throws Exception {
    final int messageSize = 3 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;
    ClientSession session = null;
    try {
        ActiveMQServer server = createServer(true, isNetty(), storeType);
        server.start();
        SimpleString ADDRESS_EXPIRY = ADDRESS.concat("-expiry");
        AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ADDRESS_EXPIRY);
        server.getAddressSettingsRepository().addMatch("*", addressSettings);
        ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
        session = sf.createSession(false, false, false);
        session.createQueue(ADDRESS, ADDRESS, 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 consumer = session.createConsumer(ADDRESS_EXPIRY);
        // Creating a consumer just to make the expiry process go faster and not have to wait for the reaper
        ClientConsumer consumer2 = session.createConsumer(ADDRESS);
        Assert.assertNull(consumer2.receiveImmediate());
        ClientMessage msg1 = consumer.receive(50000);
        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_EXPIRY);
        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();
    } finally {
        try {
            session.close();
        } catch (Throwable ignored) {
        }
    }
}
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 72 with Message

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

the class LargeMessageTest method simpleRollbackInternalTest.

public void simpleRollbackInternalTest(final boolean isXA) 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();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = sf.createSession(isXA, false, false);
    Xid xid = null;
    if (isXA) {
        xid = newXID();
        session.start(xid, XAResource.TMNOFLAGS);
    }
    session.createQueue(ADDRESS, ADDRESS, null, true);
    int numberOfBytes = 200000;
    session.start();
    ClientProducer producer = session.createProducer(ADDRESS);
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int n = 0; n < 10; n++) {
        Message clientFile = createLargeClientMessageStreaming(session, numberOfBytes, n % 2 == 0);
        producer.send(clientFile);
        Assert.assertNull(consumer.receiveImmediate());
        if (isXA) {
            session.end(xid, XAResource.TMSUCCESS);
            session.rollback(xid);
            xid = newXID();
            session.start(xid, XAResource.TMNOFLAGS);
        } else {
            session.rollback();
        }
        clientFile = createLargeClientMessageStreaming(session, numberOfBytes, n % 2 == 0);
        producer.send(clientFile);
        Assert.assertNull(consumer.receiveImmediate());
        if (isXA) {
            session.end(xid, XAResource.TMSUCCESS);
            session.commit(xid, true);
            xid = newXID();
            session.start(xid, XAResource.TMNOFLAGS);
        } else {
            session.commit();
        }
        for (int i = 0; i < 2; i++) {
            ClientMessage clientMessage = consumer.receive(5000);
            Assert.assertNotNull(clientMessage);
            Assert.assertEquals(numberOfBytes, clientMessage.getBodySize());
            clientMessage.acknowledge();
            if (isXA) {
                if (i == 0) {
                    session.end(xid, XAResource.TMSUCCESS);
                    session.prepare(xid);
                    session.rollback(xid);
                    xid = newXID();
                    session.start(xid, XAResource.TMNOFLAGS);
                } else {
                    session.end(xid, XAResource.TMSUCCESS);
                    session.commit(xid, true);
                    xid = newXID();
                    session.start(xid, XAResource.TMNOFLAGS);
                }
            } else {
                if (i == 0) {
                    session.rollback();
                } else {
                    session.commit();
                }
            }
        }
    }
    session.close();
    validateNoFilesOnLargeDir();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) 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 73 with Message

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

the class DeadLetterAddressTest method testReceiveWithListeners.

@Test
public void testReceiveWithListeners() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(2).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(qName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(qName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    final CountDownLatch latch = new CountDownLatch(2);
    TestHandler handler = new TestHandler(latch, clientSession);
    clientConsumer.setMessageHandler(handler);
    clientSession.start();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertEquals(handler.count, 2);
    clientConsumer = clientSession.createConsumer(dlq);
    Message m = clientConsumer.receive(5000);
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 74 with Message

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

the class InterruptedLargeMessageTest method testConsumeAfterRestart.

@Test
public void testConsumeAfterRestart() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    QueueFactory original = server.getQueueFactory();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    session.close();
    sf.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = cons.receive(5000);
        Assert.assertNotNull(msg);
        msg.saveToOutputStream(new java.io.OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        });
        msg.acknowledge();
        session.commit();
    }
    ((ActiveMQServerImpl) server).replaceQueueFactory(original);
    server.fail(false);
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) IOException(java.io.IOException) QueueFactory(org.apache.activemq.artemis.core.server.QueueFactory) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) 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) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 75 with Message

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

the class InterruptedLargeMessageTest method testSendPaging.

@Test
public void testSendPaging() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, createDefaultConfig(isNetty()), 10000, 20000, new HashMap<String, AddressSettings>());
    // server.getConfiguration()
    // .getIncomingInterceptorClassNames()
    // .add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    server.getPagingManager().getPageStore(ADDRESS).startPaging();
    ClientProducer producer = session.createProducer(ADDRESS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        producer.send(clientFile);
    }
    session.commit();
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 10);
    for (int h = 0; h < 5; h++) {
        session.close();
        sf.close();
        server.stop();
        server.start();
        sf = createSessionFactory(locator);
        session = sf.createSession(false, false);
        ClientConsumer cons = session.createConsumer(ADDRESS);
        session.start();
        for (int i = 0; i < 10; i++) {
            ClientMessage clientMessage = cons.receive(5000);
            Assert.assertNotNull(clientMessage);
            for (int countByte = 0; countByte < LARGE_MESSAGE_SIZE; countByte++) {
                Assert.assertEquals(ActiveMQTestBase.getSamplebyte(countByte), clientMessage.getBodyBuffer().readByte());
            }
            clientMessage.acknowledge();
        }
        if (h == 4) {
            session.commit();
        } else {
            session.rollback();
        }
        session.close();
        sf.close();
    }
    server.fail(false);
    server.start();
    validateNoFilesOnLargeDir();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) 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

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