Search in sources :

Example 26 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class DivertTest method testSingleNonExclusiveDivertWithRoutingType.

@Test
public void testSingleNonExclusiveDivertWithRoutingType() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress = "forwardAddress";
    DivertConfiguration divertConf = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    session.createQueue(new SimpleString(forwardAddress), RoutingType.ANYCAST, queueName1, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName2, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    final int numMessages = 1;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.setRoutingType(RoutingType.MULTICAST);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) 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 27 with DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class DivertTest method testSingleNonExclusiveDivert.

@Test
public void testSingleNonExclusiveDivert() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress = "forwardAddress";
    DivertConfiguration divertConf = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    session.createQueue(new SimpleString(forwardAddress), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName2, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    final int numMessages = 1;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        Assert.assertEquals("forwardAddress", message.getAddress());
        Assert.assertEquals("testAddress", message.getStringProperty(Message.HDR_ORIGINAL_ADDRESS));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        Assert.assertEquals("testAddress", message.getAddress());
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) 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 DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class DivertTest method testMixExclusiveAndNonExclusiveDiverts.

@Test
public void testMixExclusiveAndNonExclusiveDiverts() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress1).setExclusive(true);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert2").setRoutingName("divert2").setAddress(testAddress).setForwardingAddress(forwardAddress2).setExclusive(true);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert3").setRoutingName("divert3").setAddress(testAddress).setForwardingAddress(forwardAddress3);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(forwardAddress2), RoutingType.MULTICAST, queueName2, null, false);
    session.createQueue(new SimpleString(forwardAddress3), RoutingType.MULTICAST, queueName3, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName4, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
    Assert.assertNull(consumer3.receiveImmediate());
    Assert.assertNull(consumer4.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) 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 DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class DivertTest method testRoundRobinDiverts.

@Test
public void testRoundRobinDiverts() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("thename").setAddress(testAddress).setForwardingAddress(forwardAddress1);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert2").setRoutingName("thename").setAddress(testAddress).setForwardingAddress(forwardAddress2);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert3").setRoutingName("thename").setAddress(testAddress).setForwardingAddress(forwardAddress3);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(forwardAddress2), RoutingType.MULTICAST, queueName2, null, false);
    session.createQueue(new SimpleString(forwardAddress3), RoutingType.MULTICAST, queueName3, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName4, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; ) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
        i++;
        if (i == numMessages) {
            break;
        }
        message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
        i++;
        if (i == numMessages) {
            break;
        }
        message = consumer3.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
        i++;
    }
    Assert.assertNull(consumer1.receiveImmediate());
    Assert.assertNull(consumer2.receiveImmediate());
    Assert.assertNull(consumer3.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer4.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer4.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) 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 DivertConfiguration

use of org.apache.activemq.artemis.core.config.DivertConfiguration in project activemq-artemis by apache.

the class DivertTest method testMultipleExclusiveDivert.

@Test
public void testMultipleExclusiveDivert() throws Exception {
    final String testAddress = "testAddress";
    final String forwardAddress1 = "forwardAddress1";
    final String forwardAddress2 = "forwardAddress2";
    final String forwardAddress3 = "forwardAddress3";
    DivertConfiguration divertConf1 = new DivertConfiguration().setName("divert1").setRoutingName("divert1").setAddress(testAddress).setForwardingAddress(forwardAddress1).setExclusive(true);
    DivertConfiguration divertConf2 = new DivertConfiguration().setName("divert2").setRoutingName("divert2").setAddress(testAddress).setForwardingAddress(forwardAddress2).setExclusive(true);
    DivertConfiguration divertConf3 = new DivertConfiguration().setName("divert3").setRoutingName("divert3").setAddress(testAddress).setForwardingAddress(forwardAddress3).setExclusive(true);
    Configuration config = createDefaultInVMConfig().addDivertConfiguration(divertConf1).addDivertConfiguration(divertConf2).addDivertConfiguration(divertConf3);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    final SimpleString queueName1 = new SimpleString("queue1");
    final SimpleString queueName2 = new SimpleString("queue2");
    final SimpleString queueName3 = new SimpleString("queue3");
    final SimpleString queueName4 = new SimpleString("queue4");
    session.createQueue(new SimpleString(forwardAddress1), RoutingType.MULTICAST, queueName1, null, false);
    session.createQueue(new SimpleString(forwardAddress2), RoutingType.MULTICAST, queueName2, null, false);
    session.createQueue(new SimpleString(forwardAddress3), RoutingType.MULTICAST, queueName3, null, false);
    session.createQueue(new SimpleString(testAddress), RoutingType.MULTICAST, queueName4, null, false);
    session.start();
    ClientProducer producer = session.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session.createConsumer(queueName1);
    ClientConsumer consumer2 = session.createConsumer(queueName2);
    ClientConsumer consumer3 = session.createConsumer(queueName3);
    ClientConsumer consumer4 = session.createConsumer(queueName4);
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer2.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer2.receiveImmediate());
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer3.receive(DivertTest.TIMEOUT);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty(propKey).intValue());
        message.acknowledge();
    }
    Assert.assertNull(consumer3.receiveImmediate());
    Assert.assertNull(consumer4.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) 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) 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

DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)33 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)21 Configuration (org.apache.activemq.artemis.core.config.Configuration)19 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)18 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)18 Test (org.junit.Test)18 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)17 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)17 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)17 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)17 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)16 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 TransformerConfiguration (org.apache.activemq.artemis.core.config.TransformerConfiguration)4 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 Before (org.junit.Before)2 PrintStream (java.io.PrintStream)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1