Search in sources :

Example 1 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal in project activemq-artemis by apache.

the class ClusterConnectionImpl method createNewRecord.

private void createNewRecord(final long eventUID, final String targetNodeID, final TransportConfiguration connector, final SimpleString queueName, final Queue queue, final boolean start) throws Exception {
    String nodeId;
    synchronized (this) {
        if (!started) {
            return;
        }
        if (serverLocator == null) {
            return;
        }
        nodeId = serverLocator.getNodeID();
    }
    final ServerLocatorInternal targetLocator = new ServerLocatorImpl(topology, true, connector);
    targetLocator.setReconnectAttempts(0);
    targetLocator.setInitialConnectAttempts(0);
    targetLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    targetLocator.setConnectionTTL(connectionTTL);
    targetLocator.setInitialConnectAttempts(0);
    targetLocator.setConfirmationWindowSize(confirmationWindowSize);
    targetLocator.setBlockOnDurableSend(!useDuplicateDetection);
    targetLocator.setBlockOnNonDurableSend(!useDuplicateDetection);
    targetLocator.setRetryInterval(retryInterval);
    targetLocator.setMaxRetryInterval(maxRetryInterval);
    targetLocator.setRetryIntervalMultiplier(retryIntervalMultiplier);
    targetLocator.setMinLargeMessageSize(minLargeMessageSize);
    // No producer flow control on the bridges by default, as we don't want to lock the queues
    targetLocator.setProducerWindowSize(this.producerWindowSize);
    targetLocator.setAfterConnectionInternalListener(this);
    serverLocator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(serverLocator));
    targetLocator.setNodeID(nodeId);
    targetLocator.setClusterTransportConfiguration(serverLocator.getClusterTransportConfiguration());
    if (retryInterval > 0) {
        targetLocator.setRetryInterval(retryInterval);
    }
    targetLocator.disableFinalizeCheck();
    targetLocator.addIncomingInterceptor(new IncomingInterceptorLookingForExceptionMessage(manager, executorFactory.getExecutor()));
    MessageFlowRecordImpl record = new MessageFlowRecordImpl(targetLocator, eventUID, targetNodeID, connector, queueName, queue);
    ClusterConnectionBridge bridge = new ClusterConnectionBridge(this, manager, targetLocator, serverLocator, initialConnectAttempts, reconnectAttempts, retryInterval, retryIntervalMultiplier, maxRetryInterval, nodeManager.getUUID(), record.getEventUID(), record.getTargetNodeID(), record.getQueueName(), record.getQueue(), executorFactory.getExecutor(), null, null, scheduledExecutor, null, useDuplicateDetection, clusterUser, clusterPassword, server, managementService.getManagementAddress(), managementService.getManagementNotificationAddress(), record, record.getConnector(), storeAndForwardPrefix);
    targetLocator.setIdentity("(Cluster-connection-bridge::" + bridge.toString() + "::" + this.toString() + ")");
    if (logger.isDebugEnabled()) {
        logger.debug("creating record between " + this.connector + " and " + connector + bridge);
    }
    record.setBridge(bridge);
    records.put(targetNodeID, record);
    if (start) {
        bridge.start();
    }
    if (!ConfigurationImpl.checkoutDupCacheSize(serverLocator.getConfirmationWindowSize(), server.getConfiguration().getIDCacheSize())) {
        ActiveMQServerLogger.LOGGER.duplicateCacheSizeWarning(server.getConfiguration().getIDCacheSize(), serverLocator.getConfirmationWindowSize());
    }
}
Also used : IncomingInterceptorLookingForExceptionMessage(org.apache.activemq.artemis.core.server.cluster.ClusterManager.IncomingInterceptorLookingForExceptionMessage) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 2 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal 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 3 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal in project activemq-artemis by apache.

the class ClusterController method start.

@Override
public void start() throws Exception {
    if (started)
        return;
    // set the default locator that will be used to connecting to the default cluster.
    defaultLocator = locators.get(defaultClusterConnectionName);
    // create a locator for replication, either the default or the specified if not set
    if (replicatedClusterName != null && !replicatedClusterName.equals(defaultClusterConnectionName)) {
        replicationLocator = locators.get(replicatedClusterName);
        if (replicationLocator == null) {
            ActiveMQServerLogger.LOGGER.noClusterConnectionForReplicationCluster();
            replicationLocator = defaultLocator;
        }
    } else {
        replicationLocator = defaultLocator;
    }
    // latch so we know once we are connected
    replicationClusterConnectedLatch = new CountDownLatch(1);
    // and add the quorum manager as a topology listener
    if (defaultLocator != null) {
        defaultLocator.addClusterTopologyListener(quorumManager);
    }
    if (quorumManager != null) {
        // start the quorum manager
        quorumManager.start();
    }
    started = true;
    // connect all the locators in a separate thread
    for (ServerLocatorInternal serverLocatorInternal : locators.values()) {
        if (serverLocatorInternal.isConnectable()) {
            executor.execute(new ConnectRunnable(serverLocatorInternal));
        }
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 4 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal in project activemq-artemis by apache.

the class ClusterController method stop.

@Override
public void stop() throws Exception {
    // close all the locators
    for (ServerLocatorInternal serverLocatorInternal : locators.values()) {
        serverLocatorInternal.close();
    }
    // stop the quorum manager
    quorumManager.stop();
    started = false;
}
Also used : ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Example 5 with ServerLocatorInternal

use of org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal in project activemq-artemis by apache.

the class SharedNothingLiveActivation method getLocator.

private ServerLocatorInternal getLocator(ClusterConnectionConfiguration config) throws ActiveMQException {
    ServerLocatorInternal locator;
    if (config.getDiscoveryGroupName() != null) {
        DiscoveryGroupConfiguration dg = activeMQServer.getConfiguration().getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
        if (dg == null) {
            throw ActiveMQMessageBundle.BUNDLE.noDiscoveryGroupFound(dg);
        }
        locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(dg);
    } else {
        TransportConfiguration[] tcConfigs = config.getStaticConnectors() != null ? connectorNameListToArray(config.getStaticConnectors()) : null;
        locator = (ServerLocatorInternal) ActiveMQClient.createServerLocatorWithHA(tcConfigs);
    }
    return locator;
}
Also used : TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) DiscoveryGroupConfiguration(org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration) ServerLocatorInternal(org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)

Aggregations

ServerLocatorInternal (org.apache.activemq.artemis.core.client.impl.ServerLocatorInternal)16 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)6 Test (org.junit.Test)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)4 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)4 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ClusterConnectionConfiguration (org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)1 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ServerLocatorImpl (org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl)1 Topology (org.apache.activemq.artemis.core.client.impl.Topology)1 TopologyMemberImpl (org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl)1