Search in sources :

Example 26 with AddressSettings

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

the class QueueAutoCreationTest method configureAddressPolicy.

@Override
protected void configureAddressPolicy(ActiveMQServer server) {
    Configuration serverConfig = server.getConfiguration();
    serverConfig.setJournalType(JournalType.NIO);
    Map<String, AddressSettings> map = serverConfig.getAddressesSettings();
    if (map.size() == 0) {
        AddressSettings as = new AddressSettings();
        map.put("#", as);
    }
    Map.Entry<String, AddressSettings> entry = map.entrySet().iterator().next();
    AddressSettings settings = entry.getValue();
    settings.setAutoCreateQueues(true);
    System.out.println("server cofg, isauto? " + entry.getValue().isAutoCreateQueues());
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Map(java.util.Map)

Example 27 with AddressSettings

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

the class AddressSettingsTest method test2LevelWordHierarchyWithDLA.

@Test
public void test2LevelWordHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA.toString(), addressSettings);
    repos.addMatch("*", addressSettings2);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA, queueA, false);
    session.createQueue(addressB, queueB, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    cm.getBodyBuffer().writeString("A");
    ClientMessage cm2 = sendSession.createMessage(true);
    cm2.getBodyBuffer().writeString("B");
    ClientProducer cp1 = sendSession.createProducer(addressA);
    ClientProducer cp2 = sendSession.createProducer(addressB);
    cp1.send(cm);
    cp2.send(cm2);
    ClientConsumer dlqARec = session.createConsumer(dlqA);
    ClientConsumer dlqBrec = session.createConsumer(dlqB);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    message = dlqARec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("A", message.getBodyBuffer().readString());
    message = dlqBrec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("B", message.getBodyBuffer().readString());
    sendSession.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 28 with AddressSettings

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

the class AddressSettingsTest method testOverrideHierarchyWithDLA.

@Test
public void testOverrideHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setMaxDeliveryAttempts(1);
    AddressSettings addressSettings3 = new AddressSettings().setDeadLetterAddress(dlaC).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA2.toString(), addressSettings);
    repos.addMatch("add.*", addressSettings2);
    repos.addMatch("#", addressSettings3);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA2, queueA, false);
    session.createQueue(addressB2, queueB, false);
    session.createQueue(addressC, queueC, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    session.createQueue(dlaC, dlqC, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    ClientMessage cm2 = sendSession.createMessage(true);
    ClientMessage cm3 = sendSession.createMessage(true);
    ClientProducer cp1 = sendSession.createProducer(addressA2);
    ClientProducer cp2 = sendSession.createProducer(addressB2);
    ClientProducer cp3 = sendSession.createProducer(addressC);
    cp1.send(cm);
    cp2.send(cm2);
    cp3.send(cm3);
    ClientConsumer dlqCrec = session.createConsumer(dlqC);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    ClientConsumer cc3 = session.createConsumer(queueC);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc3.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    cc3.close();
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    message = dlqCrec.receive(5000);
    Assert.assertNotNull(message);
    sendSession.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 29 with AddressSettings

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

the class AddressSettingsTest method test2LevelHierarchyWithDLA.

@Test
public void test2LevelHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA.toString(), addressSettings);
    repos.addMatch("#", addressSettings2);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA, queueA, false);
    session.createQueue(addressB, queueB, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    cm.getBodyBuffer().writeString("A");
    ClientMessage cm2 = sendSession.createMessage(true);
    cm2.getBodyBuffer().writeString("B");
    ClientProducer cp1 = sendSession.createProducer(addressA);
    ClientProducer cp2 = sendSession.createProducer(addressB);
    cp1.send(cm);
    cp2.send(cm2);
    ClientConsumer dlqARec = session.createConsumer(dlqA);
    ClientConsumer dlqBrec = session.createConsumer(dlqB);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    message = dlqARec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("A", message.getBodyBuffer().readString());
    message = dlqBrec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("B", message.getBodyBuffer().readString());
    sendSession.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 30 with AddressSettings

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

the class AddressSettingsTest method testSimpleHierarchyWithDLA.

@Test
public void testSimpleHierarchyWithDLA() throws Exception {
    ActiveMQServer server = createServer(false);
    server.start();
    AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(dlaA).setMaxDeliveryAttempts(1);
    AddressSettings addressSettings2 = new AddressSettings().setDeadLetterAddress(dlaB).setMaxDeliveryAttempts(1);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(addressA.toString(), addressSettings);
    repos.addMatch(addressB.toString(), addressSettings2);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, false);
    session.createQueue(addressA, queueA, false);
    session.createQueue(addressB, queueB, false);
    session.createQueue(dlaA, dlqA, false);
    session.createQueue(dlaB, dlqB, false);
    ClientSession sendSession = sf.createSession(false, true, true);
    ClientMessage cm = sendSession.createMessage(true);
    cm.getBodyBuffer().writeString("A");
    ClientMessage cm2 = sendSession.createMessage(true);
    cm2.getBodyBuffer().writeString("B");
    ClientProducer cp1 = sendSession.createProducer(addressA);
    ClientProducer cp2 = sendSession.createProducer(addressB);
    cp1.send(cm);
    cp2.send(cm2);
    ClientConsumer dlqARec = session.createConsumer(dlqA);
    ClientConsumer dlqBrec = session.createConsumer(dlqB);
    ClientConsumer cc1 = session.createConsumer(queueA);
    ClientConsumer cc2 = session.createConsumer(queueB);
    session.start();
    ClientMessage message = cc1.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    message = cc2.receive(5000);
    Assert.assertNotNull(message);
    message.acknowledge();
    session.rollback();
    cc1.close();
    cc2.close();
    message = dlqARec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("A", message.getBodyBuffer().readString());
    message = dlqBrec.receive(5000);
    Assert.assertNotNull(message);
    Assert.assertEquals("B", message.getBodyBuffer().readString());
    sendSession.close();
    session.close();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) 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