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));
}
}
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");
}
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");
}
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();
}
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();
}
}
Aggregations