Search in sources :

Example 56 with ClientConsumer

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

the class LargeMessageCompressTest method testLargeMessageCompression.

@Test
public void testLargeMessageCompression() throws Exception {
    final int messageSize = (int) (3.5 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);
    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);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);
    for (int i = 0; i < messageSize; i++) {
        byte b = msg1.getBodyBuffer().readByte();
        assertEquals("position = " + i, getSamplebyte(i), b);
    }
    msg1.acknowledge();
    session.commit();
    consumer.close();
    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)

Example 57 with ClientConsumer

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

the class LargeMessageCompressTest method testHugeStreamingSpacesCompressed.

// This test will send 1 Gig of spaces. There shouldn't be enough memory to uncompress the file in memory
// but this will make sure we can work through compressed channels on saving it to stream
@Test
public void testHugeStreamingSpacesCompressed() throws Exception {
    final long messageSize = 1024L * 1024L;
    System.out.println("Message size = " + messageSize);
    ActiveMQServer server = createServer(true, isNetty());
    server.start();
    // big enough to hold the whole message compressed on a single message (about 1M on our tests)
    locator.setMinLargeMessageSize(100 * 1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, false, false));
    session.createQueue(ADDRESS, ADDRESS, null, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    ClientMessage clientMessage = session.createMessage(true);
    clientMessage.setBodyInputStream(new InputStream() {

        private long count;

        private boolean closed = false;

        @Override
        public void close() throws IOException {
            super.close();
            closed = true;
        }

        @Override
        public int read() throws IOException {
            if (closed) {
                throw new IOException("Stream was closed");
            }
            if (count++ < messageSize) {
                return ' ';
            } else {
                return -1;
            }
        }
    });
    producer.send(clientMessage);
    session.commit();
    // this is to make sure the message was sent as a regular message (not taking a file on server)
    validateNoFilesOnLargeDir();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);
    final AtomicLong numberOfSpaces = new AtomicLong();
    msg1.saveToOutputStream(new OutputStream() {

        @Override
        public void write(int content) {
            if (content == ' ') {
                numberOfSpaces.incrementAndGet();
            }
        }
    });
    assertEquals(messageSize, numberOfSpaces.get());
    msg1.acknowledge();
    session.commit();
    session.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) IOException(java.io.IOException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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 58 with ClientConsumer

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

the class MessageConcurrencyTest method testMessageConcurrencyAfterConsumption.

// Test that a created message can be sent via multiple producers after being consumed from a single consumer
@Test
public void testMessageConcurrencyAfterConsumption() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession consumeSession = sf.createSession();
    final ClientProducer mainProducer = consumeSession.createProducer(ADDRESS);
    consumeSession.createQueue(ADDRESS, QUEUE_NAME);
    ClientConsumer consumer = consumeSession.createConsumer(QUEUE_NAME);
    consumeSession.start();
    Set<ClientSession> sendSessions = new HashSet<>();
    final Set<Sender> senders = new HashSet<>();
    final int numSessions = 100;
    final int numMessages = 1000;
    for (int i = 0; i < numSessions; i++) {
        ClientSession sendSession = sf.createSession();
        sendSessions.add(sendSession);
        ClientProducer producer = sendSession.createProducer(ADDRESS);
        Sender sender = new Sender(numMessages, producer);
        senders.add(sender);
        sender.start();
    }
    consumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(ClientMessage message) {
            for (Sender sender : senders) {
                sender.queue.add(message);
            }
        }
    });
    for (int i = 0; i < numMessages; i++) {
        byte[] body = RandomUtil.randomBytes(1000);
        ClientMessage message = consumeSession.createMessage(false);
        message.getBodyBuffer().writeBytes(body);
        mainProducer.send(message);
    }
    for (Sender sender : senders) {
        sender.join();
        assertFalse(sender.failed);
    }
    for (ClientSession sendSession : sendSessions) {
        sendSession.close();
    }
    consumer.close();
    consumeSession.deleteQueue(QUEUE_NAME);
    consumeSession.close();
    sf.close();
}
Also used : MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 59 with ClientConsumer

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

the class AckBatchSizeTest method testAckBatchSizeZero.

/*
   * tests that when the ackBatchSize is 0 we ack every message directly
   * */
@Test
public void testAckBatchSizeZero() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    ServerLocator locator = createInVMNonHALocator().setAckBatchSize(0).setBlockOnAcknowledge(true);
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession sendSession = cf.createSession(false, true, true);
    int numMessages = 100;
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientProducer cp = sendSession.createProducer(addressA);
    for (int i = 0; i < numMessages; i++) {
        cp.send(sendSession.createMessage(false));
    }
    ClientConsumer consumer = session.createConsumer(queueA);
    session.start();
    Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
    ClientMessage[] messages = new ClientMessage[numMessages];
    for (int i = 0; i < numMessages; i++) {
        messages[i] = consumer.receive(5000);
        Assert.assertNotNull(messages[i]);
    }
    for (int i = 0; i < numMessages; i++) {
        messages[i].acknowledge();
        Assert.assertEquals(numMessages - i - 1, q.getDeliveringCount());
    }
    sendSession.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) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 60 with ClientConsumer

use of org.apache.activemq.artemis.api.core.client.ClientConsumer 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)

Aggregations

ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)720 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)642 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)624 Test (org.junit.Test)584 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)569 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)409 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)348 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)154 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)132 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)88 Configuration (org.apache.activemq.artemis.core.config.Configuration)81 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)79 CountDownLatch (java.util.concurrent.CountDownLatch)72 Queue (org.apache.activemq.artemis.core.server.Queue)63 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)62 Xid (javax.transaction.xa.Xid)55 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)52 HashMap (java.util.HashMap)48 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)46 ArrayList (java.util.ArrayList)44