Search in sources :

Example 76 with ActiveMQBuffer

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

the class PagingOrderTest method testOrder1.

@Test
public void testOrder1() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    session.close();
    session = sf.createSession(true, true, 0);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numberOfMessages / 2; i++) {
        ClientMessage message = consumer.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("id").intValue());
        if (i < 100) {
            // Do not consume the last one so we could restart
            message.acknowledge();
        }
    }
    session.close();
    sf.close();
    sf = createSessionFactory(locator);
    session = sf.createSession(true, true, 0);
    session.start();
    consumer = session.createConsumer(ADDRESS);
    for (int i = 100; i < numberOfMessages; i++) {
        ClientMessage message = consumer.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("id").intValue());
        message.acknowledge();
    }
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 77 with ActiveMQBuffer

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

the class PagingOrderTest method testOrderOverRollback.

@Test
public void testOrderOverRollback() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 3000;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false, 0);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numberOfMessages / 2; i++) {
        ClientMessage message = consumer.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("id").intValue());
        message.acknowledge();
    }
    session.rollback();
    session.close();
    session = sf.createSession(false, false, 0);
    session.start();
    consumer = session.createConsumer(ADDRESS);
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = consumer.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("id").intValue());
        message.acknowledge();
    }
    session.commit();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 78 with ActiveMQBuffer

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

the class PagingOrderTest method testOrderOverRollback2.

@Test
public void testOrderOverRollback2() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 200;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    QueueImpl queue = (QueueImpl) server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 1000 == 0) {
            session.commit();
        }
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false, 0);
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    // number of references without paging
    int numberOfRefs = queue.getNumberOfReferences();
    // consume all non-paged references
    for (int ref = 0; ref < numberOfRefs; ref++) {
        ClientMessage msg = consumer.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    session.commit();
    session.close();
    session = sf.createSession(false, false, 0);
    session.start();
    consumer = session.createConsumer(ADDRESS);
    ClientMessage msg = consumer.receive(5000);
    assertNotNull(msg);
    int msgIDRolledBack = msg.getIntProperty("id").intValue();
    msg.acknowledge();
    session.rollback();
    msg = consumer.receive(5000);
    assertNotNull(msg);
    assertEquals(msgIDRolledBack, msg.getIntProperty("id").intValue());
    session.rollback();
    session.close();
    sf.close();
    locator.close();
    server.stop();
    server.start();
    locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(0);
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false, 0);
    session.start();
    consumer = session.createConsumer(ADDRESS);
    for (int i = msgIDRolledBack; i < numberOfMessages; i++) {
        ClientMessage message = consumer.receive(5000);
        assertNotNull(message);
        assertEquals(i, message.getIntProperty("id").intValue());
        message.acknowledge();
    }
    session.commit();
    session.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ByteBuffer(java.nio.ByteBuffer) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 79 with ActiveMQBuffer

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

the class ClientProducerImpl method largeMessageSendServer.

/**
 * Used to send serverMessages through the bridges. No need to validate compression here since
 * the message is only compressed at the client
 *
 * @param sendBlocking
 * @param msgI
 * @param handler
 * @throws ActiveMQException
 */
private void largeMessageSendServer(final boolean sendBlocking, final ICoreMessage msgI, final ClientProducerCredits credits, SendAcknowledgementHandler handler) throws ActiveMQException {
    sendInitialLargeMessageHeader(msgI, credits);
    LargeBodyEncoder context = msgI.getBodyEncoder();
    final long bodySize = context.getLargeBodySize();
    context.open();
    try {
        for (long pos = 0; pos < bodySize; ) {
            final boolean lastChunk;
            final int chunkLength = (int) Math.min((bodySize - pos), minLargeMessageSize);
            final ActiveMQBuffer bodyBuffer = ActiveMQBuffers.fixedBuffer(chunkLength);
            context.encode(bodyBuffer, chunkLength);
            pos += chunkLength;
            lastChunk = pos >= bodySize;
            SendAcknowledgementHandler messageHandler = lastChunk ? handler : null;
            int creditsUsed = sessionContext.sendServerLargeMessageChunk(msgI, -1, sendBlocking, lastChunk, bodyBuffer.toByteBuffer().array(), messageHandler);
            credits.acquireCredits(creditsUsed);
        }
    } finally {
        context.close();
    }
}
Also used : LargeBodyEncoder(org.apache.activemq.artemis.core.message.LargeBodyEncoder) SendAcknowledgementHandler(org.apache.activemq.artemis.api.core.client.SendAcknowledgementHandler) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 80 with ActiveMQBuffer

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

the class ActiveMQSessionContext method sendPacketWithoutLock.

private void sendPacketWithoutLock(final Channel parameterChannel, final Packet packet) {
    packet.setChannelID(parameterChannel.getID());
    Connection conn = parameterChannel.getConnection().getTransportConnection();
    ActiveMQBuffer buffer = packet.encode(this.getCoreConnection());
    conn.write(buffer, false, false);
}
Also used : RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) CoreRemotingConnection(org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)150 Test (org.junit.Test)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)49 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)44 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)38 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)35 ByteBuffer (java.nio.ByteBuffer)34 Configuration (org.apache.activemq.artemis.core.config.Configuration)34 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)27 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)25 DatabaseStorageConfiguration (org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration)25 ArrayList (java.util.ArrayList)21 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)21 Queue (org.apache.activemq.artemis.core.server.Queue)18 HashMap (java.util.HashMap)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)15 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)15 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)14