Search in sources :

Example 1 with Transformer

use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.

the class ClusterManager method deployBridge.

public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
    if (config.getName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNotUnique();
        return;
    }
    if (config.getQueueName() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoQueue(config.getName());
        return;
    }
    if (config.getForwardingAddress() == null) {
        ActiveMQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
    }
    if (bridges.containsKey(config.getName())) {
        ActiveMQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());
        return;
    }
    Transformer transformer = server.getServiceRegistry().getBridgeTransformer(config.getName(), config.getTransformerConfiguration());
    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));
    if (binding == null) {
        ActiveMQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());
        return;
    }
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeDeployBridge(config));
    }
    Queue queue = (Queue) binding.getBindable();
    ServerLocatorInternal serverLocator;
    if (config.getDiscoveryGroupName() != null) {
        DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
        if (discoveryGroupConfiguration == null) {
            ActiveMQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
        }
    } else {
        TransportConfiguration[] tcConfigs = configuration.getTransportConfigurations(config.getStaticConnectors());
        if (tcConfigs == null) {
            ActiveMQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
            return;
        }
        if (config.isHA()) {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
        } else {
            serverLocator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithoutHA(tcConfigs);
        }
    }
    serverLocator.setIdentity("Bridge " + config.getName());
    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());
    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(0);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setConnectionTTL(config.getConnectionTTL());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    serverLocator.setProducerWindowSize(config.getProducerWindowSize());
    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    serverLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(this, executor));
    if (!config.isUseDuplicateDetection()) {
        logger.debug("Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously");
    }
    clusterLocators.add(serverLocator);
    Bridge bridge = new BridgeImpl(serverLocator, config.getInitialConnectAttempts(), config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), server);
    bridges.put(config.getName(), bridge);
    managementService.registerBridge(bridge, config);
    bridge.start();
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterDeployBridge(bridge));
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 2 with Transformer

use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.

the class ActiveMQServerImpl method deployDivert.

@Override
public void deployDivert(DivertConfiguration config) throws Exception {
    if (config.getName() == null) {
        throw ActiveMQMessageBundle.BUNDLE.divertWithNoName();
    }
    if (config.getAddress() == null) {
        ActiveMQServerLogger.LOGGER.divertWithNoAddress();
        return;
    }
    if (config.getForwardingAddress() == null) {
        ActiveMQServerLogger.LOGGER.divertWithNoForwardingAddress();
        return;
    }
    SimpleString sName = new SimpleString(config.getName());
    if (postOffice.getBinding(sName) != null) {
        ActiveMQServerLogger.LOGGER.divertBindingAlreadyExists(sName);
        return;
    }
    SimpleString sAddress = new SimpleString(config.getAddress());
    Transformer transformer = getServiceRegistry().getDivertTransformer(config.getName(), config.getTransformerConfiguration());
    Filter filter = FilterImpl.createFilter(config.getFilterString());
    Divert divert = new DivertImpl(new SimpleString(config.getForwardingAddress()), sName, new SimpleString(config.getRoutingName()), config.isExclusive(), filter, transformer, postOffice, storageManager, config.getRoutingType());
    Binding binding = new DivertBinding(storageManager.generateID(), sAddress, divert);
    postOffice.addBinding(binding);
    managementService.registerDivert(divert, config);
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) Divert(org.apache.activemq.artemis.core.server.Divert)

Example 3 with Transformer

use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.

the class ServiceRegistryImpl method getDivertTransformer.

@Override
public Transformer getDivertTransformer(String name, TransformerConfiguration transformerConfiguration) {
    Transformer transformer = divertTransformers.get(name);
    if (transformer == null && transformerConfiguration != null && transformerConfiguration.getClassName() != null) {
        transformer = instantiateTransformer(transformerConfiguration);
        addDivertTransformer(name, transformer);
    }
    return transformer;
}
Also used : Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer)

Example 4 with Transformer

use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.

the class ServiceRegistryImpl method instantiateTransformer.

private Transformer instantiateTransformer(final TransformerConfiguration transformerConfiguration) {
    Transformer transformer = null;
    if (transformerConfiguration != null && transformerConfiguration.getClassName() != null) {
        try {
            transformer = loadClass(transformerConfiguration.getClassName());
            transformer.init(Collections.unmodifiableMap(transformerConfiguration.getProperties()));
        } catch (Exception e) {
            throw ActiveMQMessageBundle.BUNDLE.errorCreatingTransformerClass(e, transformerConfiguration.getClassName());
        }
    }
    return transformer;
}
Also used : Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer)

Example 5 with Transformer

use of org.apache.activemq.artemis.core.server.transformer.Transformer in project activemq-artemis by apache.

the class DivertTest method testInjectedTransformer.

@Test
public void testInjectedTransformer() throws Exception {
    final SimpleString ADDRESS = new SimpleString("myAddress");
    final String DIVERT = "myDivert";
    ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl();
    Transformer transformer = new Transformer() {

        @Override
        public Message transform(Message message) {
            return null;
        }
    };
    serviceRegistry.addDivertTransformer(DIVERT, transformer);
    ActiveMQServer server = addServer(new ActiveMQServerImpl(null, null, null, null, serviceRegistry));
    server.start();
    server.waitForActivation(100, TimeUnit.MILLISECONDS);
    server.createQueue(ADDRESS, RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, false, false);
    server.deployDivert(new DivertConfiguration().setName(DIVERT).setAddress(ADDRESS.toString()).setForwardingAddress(ADDRESS.toString()));
    Collection<Binding> bindings = server.getPostOffice().getBindingsForAddress(ADDRESS).getBindings();
    Divert divert = null;
    for (Binding binding : bindings) {
        if (binding instanceof DivertBinding) {
            divert = ((DivertBinding) binding).getDivert();
        }
    }
    assertNotNull(divert);
    assertEquals(transformer, divert.getTransformer());
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceRegistryImpl(org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl) Transformer(org.apache.activemq.artemis.core.server.transformer.Transformer) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertBinding(org.apache.activemq.artemis.core.postoffice.impl.DivertBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) Divert(org.apache.activemq.artemis.core.server.Divert) Test(org.junit.Test)

Aggregations

Transformer (org.apache.activemq.artemis.core.server.transformer.Transformer)7 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 Binding (org.apache.activemq.artemis.core.postoffice.Binding)3 Message (org.apache.activemq.artemis.api.core.Message)2 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 Divert (org.apache.activemq.artemis.core.server.Divert)2 ActiveMQServerImpl (org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl)2 ServiceRegistryImpl (org.apache.activemq.artemis.core.server.impl.ServiceRegistryImpl)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1 ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)1 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)1 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)1 TransformerConfiguration (org.apache.activemq.artemis.core.config.TransformerConfiguration)1