Search in sources :

Example 16 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ZeroPrefetchConsumerTest method createArtemisBroker.

@Override
public EmbeddedJMS createArtemisBroker() throws Exception {
    Configuration config0 = createConfig("localhost", 0);
    String coreQueueAddress = brokerZeroQueue.getQueueName();
    AddressSettings addrSettings = new AddressSettings();
    addrSettings.setQueuePrefetch(0);
    config0.getAddressesSettings().put(coreQueueAddress, addrSettings);
    EmbeddedJMS newbroker = new EmbeddedJMS().setConfiguration(config0).setJmsConfiguration(new JMSConfigurationImpl());
    return newbroker;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) EmbeddedJMS(org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS) Configuration(org.apache.activemq.artemis.core.config.Configuration) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl)

Example 17 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ConsumerWindowSizeTest method internalTestFlowControlOnRollback.

private void internalTestFlowControlOnRollback(final boolean isLargeMessage) throws Exception {
    ActiveMQServer server = createServer(false, isNetty());
    AddressSettings settings = new AddressSettings().setMaxDeliveryAttempts(-1);
    server.getAddressSettingsRepository().addMatch("#", settings);
    ClientSession session = null;
    try {
        final int numberOfMessages = 100;
        server.start();
        locator.setConsumerWindowSize(300000);
        if (isLargeMessage) {
            // something to ensure we are using large messages
            locator.setMinLargeMessageSize(100);
        } else {
            // To make sure large messages won't kick in, we set anything large
            locator.setMinLargeMessageSize(Integer.MAX_VALUE);
        }
        ClientSessionFactory sf = createSessionFactory(locator);
        session = sf.createSession(false, false, false);
        SimpleString ADDRESS = new SimpleString("some-queue");
        session.createQueue(ADDRESS, ADDRESS, true);
        ClientProducer producer = session.createProducer(ADDRESS);
        for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = session.createMessage(true);
            msg.putIntProperty("count", i);
            msg.getBodyBuffer().writeBytes(new byte[1024]);
            producer.send(msg);
        }
        session.commit();
        ClientConsumerInternal consumer = (ClientConsumerInternal) session.createConsumer(ADDRESS);
        session.start();
        for (int repeat = 0; repeat < 100; repeat++) {
            long timeout = System.currentTimeMillis() + 2000;
            // At least 10 messages on the buffer
            while (timeout > System.currentTimeMillis() && consumer.getBufferSize() <= 10) {
                Thread.sleep(10);
            }
            Assert.assertTrue(consumer.getBufferSize() >= 10);
            ClientMessage msg = consumer.receive(500);
            msg.getBodyBuffer().readByte();
            Assert.assertNotNull(msg);
            msg.acknowledge();
            session.rollback();
        }
        for (int i = 0; i < numberOfMessages; i++) {
            ClientMessage msg = consumer.receive(5000);
            Assert.assertNotNull(msg);
            msg.getBodyBuffer().readByte();
            msg.acknowledge();
            session.commit();
        }
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (Exception ignored) {
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientConsumerInternal(org.apache.activemq.artemis.core.client.impl.ClientConsumerInternal) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) IOException(java.io.IOException)

Example 18 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class DeadLetterAddressTest method testBasicSend.

@Test
public void testBasicSend() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    SimpleString adName = new SimpleString("ad1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
    SimpleString dlq = new SimpleString("DLQ1");
    clientSession.createQueue(dla, dlq, null, false);
    clientSession.createQueue(adName, qName, null, false);
    ClientProducer producer = clientSession.createProducer(adName);
    producer.send(createTextMessage(clientSession, "heyho!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
    clientConsumer = clientSession.createConsumer(dlq);
    m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    assertEquals("q1", m.getStringProperty(Message.HDR_ORIGINAL_QUEUE));
    assertEquals("ad1", m.getStringProperty(Message.HDR_ORIGINAL_ADDRESS));
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 19 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class DeadLetterAddressTest method testDeadLetterAddressWithOverridenSublevelAddressSettings.

@Test
public void testDeadLetterAddressWithOverridenSublevelAddressSettings() throws Exception {
    int defaultDeliveryAttempt = 3;
    int specificeDeliveryAttempt = defaultDeliveryAttempt + 1;
    SimpleString address = new SimpleString("prefix.address");
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString defaultDeadLetterAddress = RandomUtil.randomSimpleString();
    SimpleString defaultDeadLetterQueue = RandomUtil.randomSimpleString();
    SimpleString specificDeadLetterAddress = RandomUtil.randomSimpleString();
    SimpleString specificDeadLetterQueue = RandomUtil.randomSimpleString();
    AddressSettings defaultAddressSettings = new AddressSettings().setMaxDeliveryAttempts(defaultDeliveryAttempt).setDeadLetterAddress(defaultDeadLetterAddress);
    server.getAddressSettingsRepository().addMatch("*", defaultAddressSettings);
    AddressSettings specificAddressSettings = new AddressSettings().setMaxDeliveryAttempts(specificeDeliveryAttempt).setDeadLetterAddress(specificDeadLetterAddress);
    server.getAddressSettingsRepository().addMatch(address.toString(), specificAddressSettings);
    clientSession.createQueue(address, queue, false);
    clientSession.createQueue(defaultDeadLetterAddress, defaultDeadLetterQueue, false);
    clientSession.createQueue(specificDeadLetterAddress, specificDeadLetterQueue, false);
    ClientProducer producer = clientSession.createProducer(address);
    ClientMessage clientMessage = createTextMessage(clientSession, "heyho!");
    producer.send(clientMessage);
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(queue);
    ClientConsumer defaultDeadLetterConsumer = clientSession.createConsumer(defaultDeadLetterQueue);
    ClientConsumer specificDeadLetterConsumer = clientSession.createConsumer(specificDeadLetterQueue);
    for (int i = 0; i < defaultDeliveryAttempt; i++) {
        ClientMessage m = clientConsumer.receive(500);
        Assert.assertNotNull(m);
        Assert.assertEquals(i + 1, m.getDeliveryCount());
        m.acknowledge();
        clientSession.rollback();
    }
    Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate());
    Assert.assertNull(specificDeadLetterConsumer.receiveImmediate());
    // one more redelivery attempt:
    ClientMessage m = clientConsumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(specificeDeliveryAttempt, m.getDeliveryCount());
    m.acknowledge();
    clientSession.rollback();
    Assert.assertNull(defaultDeadLetterConsumer.receiveImmediate());
    Assert.assertNotNull(specificDeadLetterConsumer.receive(500));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 20 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class DeadLetterAddressTest method testBasicSendWithDLAButNoBinding.

// HORNETQ- 1084
@Test
public void testBasicSendWithDLAButNoBinding() throws Exception {
    SimpleString dla = new SimpleString("DLA");
    SimpleString qName = new SimpleString("q1");
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).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!"));
    clientSession.start();
    ClientConsumer clientConsumer = clientSession.createConsumer(qName);
    ClientMessage m = clientConsumer.receive(500);
    m.acknowledge();
    Assert.assertNotNull(m);
    Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
    // force a cancel
    clientSession.rollback();
    m = clientConsumer.receiveImmediate();
    Assert.assertNull(m);
    clientConsumer.close();
    Queue q = (Queue) server.getPostOffice().getBinding(qName).getBindable();
    Assert.assertEquals(0, q.getDeliveringCount());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14