Search in sources :

Example 56 with Message

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

the class ScaleDownTest method testFilters.

@Test
public void testFilters() throws Exception {
    final int TEST_SIZE = 50;
    final String addressName = "testAddress";
    final String evenQueue = "evenQueue";
    final String oddQueue = "oddQueue";
    createQueue(0, addressName, evenQueue, "0", false);
    createQueue(0, addressName, oddQueue, "1", false);
    createQueue(1, addressName, evenQueue, "0", false);
    createQueue(1, addressName, oddQueue, "1", false);
    ClientSessionFactory sf = sfs[0];
    ClientSession session = addClientSession(sf.createSession(false, false));
    ClientProducer producer = addClientProducer(session.createProducer(addressName));
    for (int i = 0; i < TEST_SIZE; i++) {
        Message message = session.createMessage(false);
        if (i % 2 == 0)
            message.putStringProperty(ClusterTestBase.FILTER_PROP, new SimpleString("0"));
        else
            message.putStringProperty(ClusterTestBase.FILTER_PROP, new SimpleString("1"));
        producer.send(message);
    }
    session.commit();
    servers[0].stop();
    addConsumer(0, 1, evenQueue, null);
    addConsumer(1, 1, oddQueue, null);
    for (int i = 0; i < TEST_SIZE; i++) {
        String compare;
        ClientMessage message;
        if (i % 2 == 0) {
            message = consumers[0].getConsumer().receive(250);
            compare = "0";
        } else {
            message = consumers[1].getConsumer().receive(250);
            compare = "1";
        }
        Assert.assertEquals(compare, message.getStringProperty(ClusterTestBase.FILTER_PROP));
    }
    Assert.assertNull(consumers[0].getConsumer().receive(250));
    Assert.assertNull(consumers[1].getConsumer().receive(250));
    removeConsumer(0);
    removeConsumer(1);
}
Also used : 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) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 57 with Message

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

the class ServerSessionImpl method send.

@Override
public synchronized RoutingStatus send(Transaction tx, Message msg, final boolean direct, boolean noAutoCreateQueue) throws Exception {
    final Message message;
    if ((msg.getEncodeSize() > storageManager.getMaxRecordSize()) && !msg.isLargeMessage()) {
        message = messageToLargeMessage(msg);
    } else {
        message = msg;
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeSend(this, tx, message, direct, noAutoCreateQueue));
    }
    // If the protocol doesn't support flow control, we have no choice other than fail the communication
    if (!this.getRemotingConnection().isSupportsFlowControl() && pagingManager.isDiskFull()) {
        ActiveMQIOErrorException exception = ActiveMQMessageBundle.BUNDLE.diskBeyondLimit();
        this.getRemotingConnection().fail(exception);
        throw exception;
    }
    final RoutingStatus result;
    // case the id header already generated.
    if (!message.isLargeMessage()) {
        long id = storageManager.generateID();
        // This will re-encode the message
        message.setMessageID(id);
    }
    SimpleString address = message.getAddressSimpleString();
    if (defaultAddress == null && address != null) {
        defaultAddress = address;
    }
    if (address == null) {
        // We don't want to force a re-encode when the message gets sent to the consumer
        message.setAddress(defaultAddress);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("send(message=" + message + ", direct=" + direct + ") being called");
    }
    if (message.getAddress() == null) {
        // This could happen with some tests that are ignoring messages
        throw ActiveMQMessageBundle.BUNDLE.noAddress();
    }
    if (message.getAddressSimpleString().equals(managementAddress)) {
        // It's a management message
        result = handleManagementMessage(tx, message, direct);
    } else {
        result = doSend(tx, message, address, direct, noAutoCreateQueue);
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterSend(this, tx, message, direct, noAutoCreateQueue, result));
    }
    return result;
}
Also used : ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingStatus(org.apache.activemq.artemis.core.postoffice.RoutingStatus)

Example 58 with Message

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

the class PagingTest method testNoCursors.

@Test
public void testNoCursors() throws Exception {
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = locator.createSessionFactory();
    ClientSession session = sf.createSession();
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer prod = session.createProducer(ADDRESS);
    for (int i = 0; i < 100; i++) {
        Message msg = session.createMessage(true);
        msg.toCore().getBodyBuffer().writeBytes(new byte[1024]);
        prod.send(msg);
    }
    session.commit();
    session.deleteQueue(ADDRESS);
    session.close();
    sf.close();
    locator.close();
    server.stop();
    server.start();
    waitForNotPaging(server.getPagingManager().getPageStore(ADDRESS));
    server.stop();
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 59 with Message

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

the class DeleteMessagesOnStartupTest method testDeleteMessagesOnStartup.

@Test
public void testDeleteMessagesOnStartup() throws Exception {
    createStorage();
    Queue theQueue = new FakeQueue(new SimpleString(""));
    HashMap<Long, Queue> queues = new HashMap<>();
    queues.put(100L, theQueue);
    Message msg = new CoreMessage(1, 100);
    journal.storeMessage(msg);
    for (int i = 2; i < 100; i++) {
        journal.storeMessage(new CoreMessage(i, 100));
    }
    journal.storeReference(100, 1, true);
    journal.stop();
    journal.start();
    journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
    FakePostOffice postOffice = new FakePostOffice();
    journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new PostOfficeJournalLoader(postOffice, null, journal, null, null, null, null, null, queues));
    Assert.assertEquals(98, deletedMessage.size());
    for (Long messageID : deletedMessage) {
        Assert.assertTrue("messageID = " + messageID, messageID.longValue() >= 2 && messageID <= 99);
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) Test(org.junit.Test)

Example 60 with Message

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

the class LargeServerMessageImpl method copy.

@Override
public Message copy() {
    SequentialFile newfile = storageManager.createFileForLargeMessage(messageID, durable);
    Message newMessage = new LargeServerMessageImpl(this, properties, newfile, messageID);
    return newMessage;
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) Message(org.apache.activemq.artemis.api.core.Message)

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