Search in sources :

Example 16 with DivertConfiguration

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

the class DivertTopicToQueueTest method divertTopicToQueueWithSelectorTest.

@Test
public void divertTopicToQueueWithSelectorTest() throws Exception {
    final String address1 = "bss.order.workorderchanges.v1.topic";
    final String address2 = "bss.order.Consumer.cbma.workorderchanges.v1.queue";
    final String address3 = "bss.order.Consumer.pinpoint.workorderchanges.v1.queue";
    DivertConfiguration dc1 = new DivertConfiguration().setName("WorkOrderChangesCBMA-Divert").setRoutingName("WorkOrderChangesCBMA-Divert").setAddress(address1).setForwardingAddress(address2).setExclusive(false).setRoutingType(DivertConfigurationRoutingType.ANYCAST);
    DivertConfiguration dc2 = new DivertConfiguration().setName("WorkOrderChangesPinpoint-Divert").setRoutingName("WorkOrderChangesPinpoint-Divert").setAddress(address1).setForwardingAddress(address3).setExclusive(false).setRoutingType(DivertConfigurationRoutingType.ANYCAST);
    server.deployDivert(dc1);
    server.deployDivert(dc2);
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    Connection connection = factory.createConnection(null, null);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Topic topicSource = session.createTopic(address1);
    javax.jms.Queue queueTarget = session.createQueue(address2);
    javax.jms.Queue queueTarget2 = session.createQueue(address3);
    final MessageProducer producer = session.createProducer(topicSource);
    final TextMessage message = session.createTextMessage("Hello");
    message.setStringProperty("filename", "BILHANDLE");
    connection.start();
    String selector = "filename='BILHANDLE'";
    final MessageConsumer consumer = session.createConsumer(queueTarget, selector);
    final MessageConsumer consumer2 = session.createConsumer(queueTarget2, selector);
    producer.send(message);
    TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
    TextMessage receivedMessage2 = (TextMessage) consumer2.receive(1000);
    Assert.assertNotNull(receivedMessage);
    Assert.assertNotNull(receivedMessage2);
    connection.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 17 with DivertConfiguration

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

the class FileConfigurationParser method parseDivertConfiguration.

private void parseDivertConfiguration(final Element e, final Configuration mainConfig) {
    String name = e.getAttribute("name");
    String routingName = getString(e, "routing-name", null, Validators.NO_CHECK);
    String address = getString(e, "address", null, Validators.NOT_NULL_OR_EMPTY);
    String forwardingAddress = getString(e, "forwarding-address", null, Validators.NOT_NULL_OR_EMPTY);
    boolean exclusive = getBoolean(e, "exclusive", ActiveMQDefaultConfiguration.isDefaultDivertExclusive());
    String transformerClassName = getString(e, "transformer-class-name", null, Validators.NO_CHECK);
    DivertConfigurationRoutingType routingType = DivertConfigurationRoutingType.valueOf(getString(e, "routing-type", ActiveMQDefaultConfiguration.getDefaultDivertRoutingType(), Validators.DIVERT_ROUTING_TYPE));
    TransformerConfiguration transformerConfiguration = null;
    String filterString = null;
    NodeList children = e.getChildNodes();
    for (int j = 0; j < children.getLength(); j++) {
        Node child = children.item(j);
        if (child.getNodeName().equals("filter")) {
            filterString = getAttributeValue(child, "string");
        } else if (child.getNodeName().equals("transformer")) {
            transformerConfiguration = getTransformerConfiguration(child);
        }
    }
    if (transformerConfiguration == null && transformerClassName != null) {
        transformerConfiguration = getTransformerConfiguration(transformerClassName);
    }
    DivertConfiguration config = new DivertConfiguration().setName(name).setRoutingName(routingName).setAddress(address).setForwardingAddress(forwardingAddress).setExclusive(exclusive).setFilterString(filterString).setTransformerConfiguration(transformerConfiguration).setRoutingType(routingType);
    mainConfig.getDivertConfigurations().add(config);
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertConfigurationRoutingType(org.apache.activemq.artemis.core.server.DivertConfigurationRoutingType)

Example 18 with DivertConfiguration

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

the class ActiveMQServerControlImpl method createDivert.

@Override
public void createDivert(final String name, final String routingName, final String address, final String forwardingAddress, final boolean exclusive, final String filterString, final String transformerClassName, final Map<String, String> transformerProperties, final String routingType) throws Exception {
    checkStarted();
    clearIO();
    try {
        TransformerConfiguration transformerConfiguration = transformerClassName == null ? null : new TransformerConfiguration(transformerClassName).setProperties(transformerProperties);
        DivertConfiguration config = new DivertConfiguration().setName(name).setRoutingName(routingName).setAddress(address).setForwardingAddress(forwardingAddress).setExclusive(exclusive).setFilterString(filterString).setTransformerConfiguration(transformerConfiguration).setRoutingType(DivertConfigurationRoutingType.valueOf(routingType));
        server.deployDivert(config);
    } finally {
        blockOnIO();
    }
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration)

Example 19 with DivertConfiguration

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

the class FailoverWithDivertTest method addDivert.

private void addDivert(Configuration serverConfig, String source, String target, boolean exclusive) {
    List<DivertConfiguration> divertConfigs = serverConfig.getDivertConfigurations();
    DivertConfiguration newDivert = new DivertConfiguration();
    newDivert.setName("myDivert");
    newDivert.setAddress(source);
    newDivert.setForwardingAddress(target);
    newDivert.setExclusive(exclusive);
    divertConfigs.add(newDivert);
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration)

Example 20 with DivertConfiguration

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

the class PagingTest method internalMultiQueuesTest.

public void internalMultiQueuesTest(final boolean divert) throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    if (divert) {
        DivertConfiguration divert1 = new DivertConfiguration().setName("dv1").setRoutingName("nm1").setAddress(PagingTest.ADDRESS.toString()).setForwardingAddress(PagingTest.ADDRESS.toString() + "-1").setExclusive(true);
        config.addDivertConfiguration(divert1);
        DivertConfiguration divert2 = new DivertConfiguration().setName("dv2").setRoutingName("nm2").setAddress(PagingTest.ADDRESS.toString()).setForwardingAddress(PagingTest.ADDRESS.toString() + "-2").setExclusive(true);
        config.addDivertConfiguration(divert2);
    }
    server.start();
    final int numberOfMessages = 3000;
    final byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    final AtomicBoolean running = new AtomicBoolean(true);
    class TCount extends Thread {

        Queue queue;

        TCount(Queue queue) {
            this.queue = queue;
        }

        @Override
        public void run() {
            try {
                while (running.get()) {
                    // this will be overusing what some users do. flush / getCount
                    getMessagesAdded(queue);
                    getMessageCount(queue);
                    Thread.sleep(10);
                }
            } catch (InterruptedException e) {
                log.info("Thread interrupted");
            }
        }
    }
    TCount tcount1 = null;
    TCount tcount2 = null;
    try {
        {
            locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
            sf = createSessionFactory(locator);
            ClientSession session = sf.createSession(false, false, false);
            if (divert) {
                session.createQueue(PagingTest.ADDRESS + "-1", PagingTest.ADDRESS + "-1", null, true);
                session.createQueue(PagingTest.ADDRESS + "-2", PagingTest.ADDRESS + "-2", null, true);
            } else {
                session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-1", null, true);
                session.createQueue(PagingTest.ADDRESS.toString(), PagingTest.ADDRESS + "-2", null, true);
            }
            ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
            ClientMessage message = null;
            for (int i = 0; i < numberOfMessages; i++) {
                if (i % 500 == 0) {
                    log.info("Sent " + i + " messages");
                    session.commit();
                }
                message = session.createMessage(true);
                ActiveMQBuffer bodyLocal = message.getBodyBuffer();
                bodyLocal.writeBytes(body);
                message.putIntProperty(new SimpleString("id"), i);
                producer.send(message);
            }
            session.commit();
            session.close();
            server.stop();
            sf.close();
            locator.close();
        }
        server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
        server.start();
        Queue queue1 = server.locateQueue(PagingTest.ADDRESS.concat("-1"));
        Queue queue2 = server.locateQueue(PagingTest.ADDRESS.concat("-2"));
        assertNotNull(queue1);
        assertNotNull(queue2);
        assertNotSame(queue1, queue2);
        tcount1 = new TCount(queue1);
        tcount2 = new TCount(queue2);
        tcount1.start();
        tcount2.start();
        locator = createInVMNonHALocator();
        final ClientSessionFactory sf2 = createSessionFactory(locator);
        final AtomicInteger errors = new AtomicInteger(0);
        Thread[] threads = new Thread[2];
        for (int start = 1; start <= 2; start++) {
            final String addressToSubscribe = PagingTest.ADDRESS + "-" + start;
            threads[start - 1] = new Thread() {

                @Override
                public void run() {
                    try {
                        ClientSession session = sf2.createSession(null, null, false, true, true, false, 0);
                        ClientConsumer consumer = session.createConsumer(addressToSubscribe);
                        session.start();
                        for (int i = 0; i < numberOfMessages; i++) {
                            ClientMessage message2 = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
                            Assert.assertNotNull(message2);
                            Assert.assertEquals(i, message2.getIntProperty("id").intValue());
                            message2.acknowledge();
                            Assert.assertNotNull(message2);
                            if (i % 100 == 0) {
                                if (i % 5000 == 0) {
                                    log.info(addressToSubscribe + " consumed " + i + " messages");
                                }
                                session.commit();
                            }
                            try {
                                assertBodiesEqual(body, message2.getBodyBuffer());
                            } catch (AssertionError e) {
                                PagingTest.log.info("Expected buffer:" + ActiveMQTestBase.dumpBytesHex(body, 40));
                                PagingTest.log.info("Arriving buffer:" + ActiveMQTestBase.dumpBytesHex(message2.getBodyBuffer().toByteBuffer().array(), 40));
                                throw e;
                            }
                        }
                        session.commit();
                        consumer.close();
                        session.close();
                    } catch (Throwable e) {
                        e.printStackTrace();
                        errors.incrementAndGet();
                    }
                }
            };
        }
        for (int i = 0; i < 2; i++) {
            threads[i].start();
        }
        for (int i = 0; i < 2; i++) {
            threads[i].join();
        }
        sf2.close();
        locator.close();
        assertEquals(0, errors.get());
        for (int i = 0; i < 20 && server.getPagingManager().getTransactions().size() != 0; i++) {
            if (server.getPagingManager().getTransactions().size() != 0) {
                // The delete may be asynchronous, giving some time case it eventually happen asynchronously
                Thread.sleep(500);
            }
        }
        assertEquals(0, server.getPagingManager().getTransactions().size());
    } finally {
        running.set(false);
        if (tcount1 != null) {
            tcount1.interrupt();
            tcount1.join();
        }
        if (tcount2 != null) {
            tcount2.interrupt();
            tcount2.join();
        }
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
    }
}
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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

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