From 3259791bbb54e6241246618bb8f097370976cc34 Mon Sep 17 00:00:00 2001 From: gtully Date: Tue, 19 Oct 2021 17:10:42 +0100 Subject: [PATCH] ARTEMIS-3533 - respect extra url parameters from federation connector-ref --- .../server/federation/FederationConnection.java | 15 +++++++++++++++ .../FederatedServerLocatorConfigTest.java | 13 ++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/federation/FederationConnection.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/federation/FederationConnection.java index b88617f685..bcbdc1cb2b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/federation/FederationConnection.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/federation/FederationConnection.java @@ -17,6 +17,7 @@ package org.apache.activemq.artemis.core.server.federation; +import java.util.Map; import org.apache.activemq.artemis.api.core.ActiveMQSessionCreationException; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.artemis.api.core.TransportConfiguration; @@ -26,6 +27,7 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.federation.FederationConnectionConfiguration; import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; +import org.apache.activemq.artemis.utils.uri.BeanSupport; public class FederationConnection { @@ -39,6 +41,7 @@ public class FederationConnection { public FederationConnection(Configuration configuration, String name, FederationConnectionConfiguration config) { this.config = config; this.circuitBreakerTimeout = config.getCircuitBreakerTimeout(); + Map possibleLocatorParameters = null; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (discoveryGroupConfiguration == null) { @@ -67,6 +70,10 @@ public class FederationConnection { } else { serverLocator = ActiveMQClient.createServerLocatorWithoutHA(tcConfigs); } + + if (tcConfigs.length > 0) { + possibleLocatorParameters = tcConfigs[0].getExtraParams(); + } } if (!config.isHA()) { @@ -83,6 +90,14 @@ public class FederationConnection { serverLocator.setCallTimeout(config.getCallTimeout()); serverLocator.setCallFailoverTimeout(config.getCallFailoverTimeout()); + // let url parameters override + if (possibleLocatorParameters != null) { + try { + BeanSupport.setData(serverLocator, possibleLocatorParameters); + } catch (Exception ignoredAsErrorsVisibleViaBeanUtilsLogging) { + } + } + } public synchronized void start() { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/federation/FederatedServerLocatorConfigTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/federation/FederatedServerLocatorConfigTest.java index c40d35bb44..e1745f8623 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/federation/FederatedServerLocatorConfigTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/federation/FederatedServerLocatorConfigTest.java @@ -17,7 +17,6 @@ package org.apache.activemq.artemis.tests.integration.federation; import java.util.HashMap; -import java.util.Map; import org.apache.activemq.artemis.api.core.TransportConfiguration; import org.apache.activemq.artemis.core.config.Configuration; @@ -60,14 +59,8 @@ public class FederatedServerLocatorConfigTest extends FederatedTestBase { public void testFederatedAddressServerLocatorConfigFromUrl() throws Exception { String address = getName(); - // we still won't pick up url params, restricted locator config is explicit - // bundling getUseTopologyForLoadBalancing with HA=false is consistent with simplification String connectorName = "server1WithUrlParams"; - Map params = new HashMap<>(); - params.put("host", "localhost"); - params.put("port", org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_PORT + 1); - - getServer(0).getConfiguration().addConnectorConfiguration(connectorName, new TransportConfiguration(NETTY_CONNECTOR_FACTORY, params)); + getServer(0).getConfiguration().addConnectorConfiguration(connectorName, "tcp://localhost:" + (org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_PORT + 1) + "?ackBatchSize=100&consumerWindowSize=-1"); FederationConfiguration federationConfiguration0 = FederatedTestUtil.createAddressUpstreamFederationConfiguration("server1WithUrlParams", address, 2); for (FederationUpstreamConfiguration upstreamConfiguration : federationConfiguration0.getUpstreamConfigurations()) { @@ -77,10 +70,12 @@ public class FederatedServerLocatorConfigTest extends FederatedTestBase { getServer(0).getFederationManager().deploy(); - // lets peek at the server locator + // let's peek at the server locator Federation fed = getServer(0).getFederationManager().get(federationConfiguration0.getName()); assertNotNull(fed); FederationUpstream federationUpstream = fed.get(connectorName); assertFalse(federationUpstream.getConnection().clientSessionFactory().getServerLocator().getUseTopologyForLoadBalancing()); + assertEquals(100, federationUpstream.getConnection().clientSessionFactory().getServerLocator().getAckBatchSize()); + assertEquals(-1, federationUpstream.getConnection().clientSessionFactory().getServerLocator().getConsumerWindowSize()); } }