Search in sources :

Example 6 with TransformerConfiguration

use of org.apache.activemq.artemis.core.config.TransformerConfiguration 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 7 with TransformerConfiguration

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

the class BridgeTest method internaltestWithTransformer.

private void internaltestWithTransformer(final boolean useFiles) throws Exception {
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, false, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, false, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setTransformerConfiguration(new TransformerConfiguration(SimpleTransformer.class.getName())).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1024).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("wibble");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.putStringProperty(propKey, new SimpleString("bing"));
        message.getBodyBuffer().writeString("doo be doo be doo be doo");
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);
        Assert.assertNotNull(message);
        SimpleString val = (SimpleString) message.getObjectProperty(propKey);
        Assert.assertEquals(new SimpleString("bong"), val);
        String sval = message.getBodyBuffer().readString();
        Assert.assertEquals("dee be dee be dee be dee", sval);
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    if (server0.getConfiguration().isPersistenceEnabled()) {
        assertEquals(0, loadQueues(server0).size());
    }
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 8 with TransformerConfiguration

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

the class BridgeTest method testWithTransformerProperties.

@Test
public void testWithTransformerProperties() throws Exception {
    final String propKey = "bridged";
    final String propValue = "true";
    TransformerConfiguration transformerConfiguration = new TransformerConfiguration(AddHeadersTransformer.class.getName());
    transformerConfiguration.getProperties().put(propKey, propValue);
    Map<String, Object> server0Params = new HashMap<>();
    server0 = createClusteredServerWithParams(isNetty(), 0, false, server0Params);
    Map<String, Object> server1Params = new HashMap<>();
    addTargetParameters(server1Params);
    server1 = createClusteredServerWithParams(isNetty(), 1, false, server1Params);
    final String testAddress = "testAddress";
    final String queueName0 = "queue0";
    final String forwardAddress = "forwardAddress";
    final String queueName1 = "queue1";
    Map<String, TransportConfiguration> connectors = new HashMap<>();
    TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
    TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
    connectors.put(server1tc.getName(), server1tc);
    server0.getConfiguration().setConnectorConfigurations(connectors);
    ArrayList<String> staticConnectors = new ArrayList<>();
    staticConnectors.add(server1tc.getName());
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setTransformerConfiguration(transformerConfiguration).setRetryInterval(1000).setReconnectAttemptsOnSameNode(-1).setUseDuplicateDetection(false).setConfirmationWindowSize(1024).setStaticConnectors(staticConnectors);
    List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
    bridgeConfigs.add(bridgeConfiguration);
    server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
    CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
    List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
    queueConfigs0.add(queueConfig0);
    server0.getConfiguration().setQueueConfigurations(queueConfigs0);
    CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration().setAddress(forwardAddress).setName(queueName1);
    List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<>();
    queueConfigs1.add(queueConfig1);
    server1.getConfiguration().setQueueConfigurations(queueConfigs1);
    server1.start();
    server0.start();
    locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
    ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
    ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
    ClientSession session0 = sf0.createSession(false, true, true);
    ClientSession session1 = sf1.createSession(false, true, true);
    ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
    ClientConsumer consumer1 = session1.createConsumer(queueName1);
    session1.start();
    final int numMessages = 10;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session0.createMessage(true);
        message.getBodyBuffer().writeString("doo be doo be doo be doo");
        producer0.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);
        Assert.assertNotNull(message);
        String messagePropVal = message.getStringProperty(propKey);
        Assert.assertEquals(propValue, messagePropVal);
        String sval = message.getBodyBuffer().readString();
        Assert.assertEquals("doo be doo be doo be doo", sval);
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    session0.close();
    session1.close();
    sf0.close();
    sf1.close();
    if (server0.getConfiguration().isPersistenceEnabled()) {
        assertEquals(0, loadQueues(server0).size());
    }
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) AddHeadersTransformer(org.apache.activemq.artemis.core.server.transformer.AddHeadersTransformer) 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) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 9 with TransformerConfiguration

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

the class DivertControlTest method setUp.

// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    CoreQueueConfiguration queueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false);
    CoreQueueConfiguration forwardQueueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false);
    divertConfig = new DivertConfiguration().setName(RandomUtil.randomString()).setRoutingName(RandomUtil.randomString()).setAddress(queueConfig.getAddress()).setForwardingAddress(forwardQueueConfig.getAddress()).setExclusive(RandomUtil.randomBoolean()).setTransformerConfiguration(new TransformerConfiguration(AddHeadersTransformer.class.getName()));
    TransportConfiguration connectorConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
    Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true).addQueueConfiguration(queueConfig).addQueueConfiguration(forwardQueueConfig).addDivertConfiguration(divertConfig).addConnectorConfiguration(connectorConfig.getName(), connectorConfig);
    server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, false));
    server.start();
}
Also used : TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) AddHeadersTransformer(org.apache.activemq.artemis.core.server.transformer.AddHeadersTransformer) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransformerConfiguration(org.apache.activemq.artemis.core.config.TransformerConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Before(org.junit.Before)

Aggregations

TransformerConfiguration (org.apache.activemq.artemis.core.config.TransformerConfiguration)9 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)5 ArrayList (java.util.ArrayList)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)3 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)3 HashMap (java.util.HashMap)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 AddHeadersTransformer (org.apache.activemq.artemis.core.server.transformer.AddHeadersTransformer)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 DivertConfigurationRoutingType (org.apache.activemq.artemis.core.server.DivertConfigurationRoutingType)1 Before (org.junit.Before)1 Test (org.junit.Test)1