Search in sources :

Example 1 with BridgeImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl 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 BridgeImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl in project activemq-artemis by apache.

the class BindingsClusterTest method getForwardingConnection.

private RemotingConnection getForwardingConnection(final Bridge bridge) throws Exception {
    long start = System.currentTimeMillis();
    do {
        RemotingConnection forwardingConnection = ((BridgeImpl) bridge).getForwardingConnection();
        if (forwardingConnection != null) {
            return forwardingConnection;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < 50000);
    throw new IllegalStateException("Failed to get forwarding connection");
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 3 with BridgeImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl in project activemq-artemis by apache.

the class BridgeReconnectTest method getForwardingConnection.

private RemotingConnection getForwardingConnection(final Bridge bridge) throws Exception {
    long start = System.currentTimeMillis();
    do {
        RemotingConnection forwardingConnection = ((BridgeImpl) bridge).getForwardingConnection();
        if (forwardingConnection != null) {
            return forwardingConnection;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < 50000);
    throw new IllegalStateException("Failed to get forwarding connection");
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 4 with BridgeImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl in project activemq-artemis by apache.

the class BridgeFailoverTest method internalTestFailoverOnBridge.

public void internalTestFailoverOnBridge(int retriesSameNode) throws Exception {
    BridgeConfiguration bridgeConfiguration = new BridgeConfiguration();
    String ORIGINAL_QUEUE = "noCluster.originalQueue";
    String TARGET_QUEUE = "noCluster.targetQueue";
    bridgeConfiguration.setHA(true);
    List<String> connectors = new ArrayList<>();
    connectors.add("target-4");
    connectors.add("backup-4");
    bridgeConfiguration.setName("Bridge-for-test");
    bridgeConfiguration.setStaticConnectors(connectors);
    bridgeConfiguration.setQueueName(ORIGINAL_QUEUE);
    bridgeConfiguration.setForwardingAddress(TARGET_QUEUE);
    bridgeConfiguration.setRetryInterval(100);
    bridgeConfiguration.setConfirmationWindowSize(1);
    bridgeConfiguration.setReconnectAttempts(-1);
    bridgeConfiguration.setReconnectAttemptsOnSameNode(retriesSameNode);
    bridgeConfiguration.setHA(true);
    servers[2].getConfiguration().getBridgeConfigurations().add(bridgeConfiguration);
    for (ActiveMQServer server : servers) {
        server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(ORIGINAL_QUEUE).setName(ORIGINAL_QUEUE));
        server.getConfiguration().getQueueConfigurations().add(new CoreQueueConfiguration().setAddress(TARGET_QUEUE).setName(TARGET_QUEUE));
    }
    startServers();
    BridgeImpl bridge = (BridgeImpl) servers[2].getClusterManager().getBridges().get("Bridge-for-test");
    assertNotNull(bridge);
    long timeout = System.currentTimeMillis() + 5000;
    while (bridge.getTargetNodeFromTopology() == null && timeout > System.currentTimeMillis()) {
        Thread.sleep(100);
    }
    assertNotNull(bridge.getTargetNodeFromTopology());
    // The server where the bridge source is configured at
    ServerLocator locatorProducer = createLocator(false, 2);
    ClientSessionFactory factory = addSessionFactory(locatorProducer.createSessionFactory());
    ClientSession session = addClientSession(factory.createSession(false, false));
    ClientProducer producer = addClientProducer(session.createProducer(ORIGINAL_QUEUE));
    for (int i = 0; i < 100; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("i", i);
        producer.send(msg);
    }
    session.commit();
    ServerLocator locatorConsumer = createLocator(false, 4);
    ClientSessionFactory factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
    ClientSession sessionConsumer = addClientSession(factoryConsumer.createSession(false, false));
    ClientConsumer consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
    sessionConsumer.start();
    for (int i = 0; i < 100; i++) {
        ClientMessage message = consumer.receive(10000);
        assertNotNull(message);
        message.acknowledge();
    }
    // We rollback as we will receive them again
    sessionConsumer.rollback();
    factoryConsumer.close();
    sessionConsumer.close();
    crashAndWaitForFailure(servers[4], locatorConsumer);
    locatorConsumer.close();
    assertTrue("Backup server didn't activate.", backupServers[4].waitForActivation(5, TimeUnit.SECONDS));
    for (int i = 100; i < 200; i++) {
        ClientMessage msg = session.createMessage(true);
        msg.putIntProperty("i", i);
        producer.send(msg);
    }
    session.commit();
    locatorConsumer = createLocator(false, 9);
    factoryConsumer = addSessionFactory(locatorConsumer.createSessionFactory());
    sessionConsumer = addClientSession(factoryConsumer.createSession());
    consumer = sessionConsumer.createConsumer(TARGET_QUEUE);
    sessionConsumer.start();
    for (int i = 0; i < 200; i++) {
        ClientMessage message = consumer.receive(10000);
        assertNotNull(message);
        message.acknowledge();
    }
    sessionConsumer.commit();
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) BridgeConfiguration(org.apache.activemq.artemis.core.config.BridgeConfiguration) ArrayList(java.util.ArrayList) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Example 5 with BridgeImpl

use of org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl in project activemq-artemis by apache.

the class BindingsClusterTest method crash.

private void crash() throws Exception {
    /*
       * Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure
       * so the bridge's failure listener needs to get something other than a DISCONNECTED message.  In this case we
       * simulate a NOT_CONNECTED exception.
       */
    final CountDownLatch latch = new CountDownLatch(1);
    ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next();
    BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge();
    RemotingConnection forwardingConnection = getForwardingConnection(bridge);
    forwardingConnection.addFailureListener(new FailureListener() {

        @Override
        public void connectionFailed(ActiveMQException exception, boolean failedOver) {
            latch.countDown();
        }

        @Override
        public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
            connectionFailed(me, failedOver);
        }
    });
    forwardingConnection.fail(new ActiveMQNotConnectedException());
    assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
    if (crash) {
        jmsServer2.stop();
    }
}
Also used : BridgeImpl(org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) FailureListener(org.apache.activemq.artemis.core.remoting.FailureListener) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterConnectionImpl(org.apache.activemq.artemis.core.server.cluster.impl.ClusterConnectionImpl)

Aggregations

BridgeImpl (org.apache.activemq.artemis.core.server.cluster.impl.BridgeImpl)5 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)1 BridgeConfiguration (org.apache.activemq.artemis.core.config.BridgeConfiguration)1 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)1 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 FailureListener (org.apache.activemq.artemis.core.remoting.FailureListener)1