ARTEMIS-2904 prevent acceptor from automatically starting

This commit is contained in:
Justin Bertram 2020-09-17 10:24:28 -05:00 committed by Clebert Suconic
parent 10a444109b
commit beaacbfa8d
5 changed files with 32 additions and 0 deletions

View File

@ -186,6 +186,10 @@ public class TransportConstants {
public static final String PROXY_REMOTE_DNS_PROP_NAME = "socksRemoteDNS"; public static final String PROXY_REMOTE_DNS_PROP_NAME = "socksRemoteDNS";
public static final String AUTO_START = "autoStart";
public static final boolean DEFAULT_AUTO_START = true;
public static final boolean DEFAULT_SSL_ENABLED = false; public static final boolean DEFAULT_SSL_ENABLED = false;
public static final String DEFAULT_SSL_KRB5_CONFIG = null; public static final String DEFAULT_SSL_KRB5_CONFIG = null;
@ -420,6 +424,7 @@ public class TransportConstants {
allowableAcceptorKeys.add(TransportConstants.SHUTDOWN_TIMEOUT); allowableAcceptorKeys.add(TransportConstants.SHUTDOWN_TIMEOUT);
allowableAcceptorKeys.add(TransportConstants.QUIET_PERIOD); allowableAcceptorKeys.add(TransportConstants.QUIET_PERIOD);
allowableAcceptorKeys.add(TransportConstants.DISABLE_STOMP_SERVER_HEADER); allowableAcceptorKeys.add(TransportConstants.DISABLE_STOMP_SERVER_HEADER);
allowableAcceptorKeys.add(TransportConstants.AUTO_START);
ALLOWABLE_ACCEPTOR_KEYS = Collections.unmodifiableSet(allowableAcceptorKeys); ALLOWABLE_ACCEPTOR_KEYS = Collections.unmodifiableSet(allowableAcceptorKeys);

View File

@ -229,6 +229,8 @@ public class NettyAcceptor extends AbstractAcceptor {
private Map<String, Object> extraConfigs; private Map<String, Object> extraConfigs;
private final boolean autoStart;
final AtomicBoolean warningPrinted = new AtomicBoolean(false); final AtomicBoolean warningPrinted = new AtomicBoolean(false);
@ -341,6 +343,8 @@ public class NettyAcceptor extends AbstractAcceptor {
httpUpgradeEnabled = ConfigurationHelper.getBooleanProperty(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME, TransportConstants.DEFAULT_HTTP_UPGRADE_ENABLED, configuration); httpUpgradeEnabled = ConfigurationHelper.getBooleanProperty(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME, TransportConstants.DEFAULT_HTTP_UPGRADE_ENABLED, configuration);
connectionsAllowed = ConfigurationHelper.getLongProperty(TransportConstants.CONNECTIONS_ALLOWED, TransportConstants.DEFAULT_CONNECTIONS_ALLOWED, configuration); connectionsAllowed = ConfigurationHelper.getLongProperty(TransportConstants.CONNECTIONS_ALLOWED, TransportConstants.DEFAULT_CONNECTIONS_ALLOWED, configuration);
autoStart = ConfigurationHelper.getBooleanProperty(TransportConstants.AUTO_START, TransportConstants.DEFAULT_AUTO_START, configuration);
} }
@Override @Override
@ -1017,4 +1021,8 @@ public class NettyAcceptor extends AbstractAcceptor {
return (list.size() < 2 ? throwable : list.get(list.size() - 1)); return (list.size() < 2 ? throwable : list.get(list.size() - 1));
} }
} }
public boolean isAutoStart() {
return autoStart;
}
} }

View File

@ -49,6 +49,7 @@ import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.ConfigurationUtils; import org.apache.activemq.artemis.core.config.ConfigurationUtils;
import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection; import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection;
import org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory; import org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.remoting.server.RemotingService; import org.apache.activemq.artemis.core.remoting.server.RemotingService;
import org.apache.activemq.artemis.core.security.ActiveMQPrincipal; import org.apache.activemq.artemis.core.security.ActiveMQPrincipal;
@ -310,6 +311,9 @@ public class RemotingServiceImpl implements RemotingService, ServerConnectionLif
if (isStarted()) { if (isStarted()) {
for (Acceptor a : acceptors.values()) { for (Acceptor a : acceptors.values()) {
try { try {
if (a instanceof NettyAcceptor && !((NettyAcceptor)a).isAutoStart()) {
continue;
}
a.start(); a.start();
} catch (Throwable t) { } catch (Throwable t) {
ActiveMQServerLogger.LOGGER.errorStartingAcceptor(a.getName(), a.getConfiguration()); ActiveMQServerLogger.LOGGER.errorStartingAcceptor(a.getName(), a.getConfiguration());

View File

@ -260,6 +260,9 @@ simple TCP:
value. When set value to zero or negative integer this feature is turned off. value. When set value to zero or negative integer this feature is turned off.
Changing value needs to restart server to take effect. Changing value needs to restart server to take effect.
- `autoStart`. Determines whether or not an acceptor will start automatically
when the broker is started. Default value is `true`.
### Configuring Netty Native Transport ### Configuring Netty Native Transport
Netty Native Transport support exists for selected OS platforms. This allows Netty Native Transport support exists for selected OS platforms. This allows

View File

@ -28,6 +28,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.server.ActiveMQComponent; import org.apache.activemq.artemis.core.server.ActiveMQComponent;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager; import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler; import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection; import org.apache.activemq.artemis.spi.core.remoting.Connection;
@ -111,4 +112,15 @@ public class NettyAcceptorTest extends ActiveMQTestBase {
Assert.assertTrue(PortCheckRule.checkAvailable(TransportConstants.DEFAULT_PORT)); Assert.assertTrue(PortCheckRule.checkAvailable(TransportConstants.DEFAULT_PORT));
} }
@Test
public void testAutoStart() throws Exception {
ActiveMQServer server = createServer(false, createDefaultInVMConfig());
server.getConfiguration().addAcceptorConfiguration("default", "tcp://127.0.0.1:61617");
server.getConfiguration().addAcceptorConfiguration("start", "tcp://127.0.0.1:61618?autoStart=true");
server.getConfiguration().addAcceptorConfiguration("noStart", "tcp://127.0.0.1:61619?autoStart=false");
server.start();
assertTrue(server.getRemotingService().getAcceptor("default").isStarted());
assertTrue(server.getRemotingService().getAcceptor("start").isStarted());
assertFalse(server.getRemotingService().getAcceptor("noStart").isStarted());
}
} }