Search in sources :

Example 26 with Message

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

the class LargeMessageTest method internalTestSendRollback.

private void internalTestSendRollback(final boolean isXA, final boolean durable) throws Exception {
    ClientSession session = null;
    ActiveMQServer server = createServer(true, isNetty(), storeType);
    server.start();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    session = sf.createSession(isXA, false, false);
    session.createQueue(ADDRESS, ADDRESS, true);
    Xid xid = null;
    if (isXA) {
        xid = RandomUtil.randomXid();
        session.start(xid, XAResource.TMNOFLAGS);
    }
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, 50000, durable);
    for (int i = 0; i < 1; i++) {
        producer.send(clientFile);
    }
    if (isXA) {
        session.end(xid, XAResource.TMSUCCESS);
        session.prepare(xid);
        session.close();
        server.stop();
        server.start();
        sf = createSessionFactory(locator);
        session = sf.createSession(isXA, false, false);
        session.rollback(xid);
    } else {
        session.rollback();
    }
    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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 27 with Message

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

Example 28 with Message

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

the class LargeMessageTest method testDeliveryCount.

@Test
public void testDeliveryCount() 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 = sf.createSession(false, false, false);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);
    producer.send(clientFile);
    session.commit();
    session.start();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg = consumer.receive(10000);
    Assert.assertNotNull(msg);
    msg.acknowledge();
    Assert.assertEquals(1, msg.getDeliveryCount());
    log.info("body buffer is " + msg.getBodyBuffer());
    for (int i = 0; i < messageSize; i++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg.getBodyBuffer().readByte());
    }
    session.rollback();
    session.close();
    session = sf.createSession(false, false, false);
    session.start();
    consumer = session.createConsumer(ADDRESS);
    msg = consumer.receive(10000);
    Assert.assertNotNull(msg);
    msg.acknowledge();
    for (int i = 0; i < messageSize; i++) {
        Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i), msg.getBodyBuffer().readByte());
    }
    Assert.assertEquals(2, msg.getDeliveryCount());
    msg.acknowledge();
    consumer.close();
    session.commit();
    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 29 with Message

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

the class ServerConsumerImpl method proceedDeliver.

@Override
public void proceedDeliver(MessageReference reference) throws Exception {
    try {
        Message message = reference.getMessage();
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.beforeDeliver(this, reference));
        }
        if (message.isLargeMessage() && supportLargeMessage) {
            if (largeMessageDeliverer == null) {
                // This can't really happen as handle had already crated the deliverer
                // instead of throwing an exception in weird cases there is no problem on just go ahead and create it
                // again here
                largeMessageDeliverer = new LargeMessageDeliverer((LargeServerMessage) message, reference);
            }
            // The deliverer was prepared during handle, as we can't have more than one pending large message
            // as it would return busy if there is anything pending
            largeMessageDeliverer.deliver();
        } else {
            deliverStandardMessage(reference, message);
        }
    } finally {
        lockDelivery.readLock().unlock();
        callback.afterDelivery();
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterDeliver(this, reference));
        }
    }
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage)

Example 30 with Message

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

the class ServerConsumerImpl method forceDelivery.

/**
 * Prompt delivery and send a "forced delivery" message to the consumer.
 * <p>
 * When the consumer receives such a "forced delivery" message, it discards it and knows that
 * there are no other messages to be delivered.
 */
@Override
public void forceDelivery(final long sequence) {
    forceDelivery(sequence, () -> {
        Message forcedDeliveryMessage = new CoreMessage(storageManager.generateID(), 50);
        forcedDeliveryMessage.putLongProperty(ClientConsumerImpl.FORCED_DELIVERY_MESSAGE, sequence);
        forcedDeliveryMessage.setAddress(messageQueue.getName());
        applyPrefixForLegacyConsumer(forcedDeliveryMessage);
        callback.sendMessage(null, forcedDeliveryMessage, ServerConsumerImpl.this, 0);
    });
}
Also used : LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

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