This commit is contained in:
Justin Bertram 2021-03-17 09:52:13 -05:00
commit d718a9dd32
5 changed files with 126 additions and 13 deletions

View File

@ -153,6 +153,55 @@ public class FileBrokerTest {
} }
} }
@Test
public void testConfigFileReloadNegative() throws Exception {
ServerDTO serverDTO = new ServerDTO();
serverDTO.configuration = "broker-reload-disabled.xml";
FileBroker broker = null;
String path = null;
try {
SecurityConfiguration securityConfiguration = new SecurityConfiguration();
securityConfiguration.addUser("myUser", "myPass");
securityConfiguration.addRole("myUser", "guest");
ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfiguration);
broker = new FileBroker(serverDTO, securityManager, null);
broker.start();
ActiveMQServerImpl activeMQServer = (ActiveMQServerImpl) broker.getComponents().get("core");
Assert.assertNotNull(activeMQServer);
Assert.assertTrue(activeMQServer.isStarted());
Assert.assertTrue(broker.isStarted());
File file = new File(activeMQServer.getConfiguration().getConfigurationUrl().toURI());
path = file.getPath();
Assert.assertNotNull(activeMQServer.getConfiguration().getConfigurationUrl());
Thread.sleep(1000);
ServerLocator locator = ActiveMQClient.createServerLocator("tcp://localhost:61616");
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession("myUser", "myPass", false, true, false, false, 0);
ClientProducer producer = session.createProducer("DLQ");
producer.send(session.createMessage(true));
replacePatternInFile(path, "guest", "X");
Thread.sleep(1000);
try {
producer.send(session.createMessage(true));
} catch (Exception e) {
fail("Should not throw an exception: " + e.getMessage());
}
locator.close();
} finally {
assert broker != null;
broker.stop();
if (path != null) {
replacePatternInFile(path, "X", "guest");
}
}
}
private void replacePatternInFile(String file, String regex, String replacement) throws IOException { private void replacePatternInFile(String file, String regex, String replacement) throws IOException {
Path path = Paths.get(file); Path path = Paths.get(file);
Charset charset = StandardCharsets.UTF_8; Charset charset = StandardCharsets.UTF_8;

View File

@ -0,0 +1,61 @@
<?xml version='1.0'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<configuration xmlns="urn:activemq">
<jms xmlns="urn:activemq:jms">
<queue name="DLQ"/>
<queue name="ExpiryQueue"/>
</jms>
<core xmlns="urn:activemq:core">
<paging-directory>./target/paging</paging-directory>
<bindings-directory>./target/bindings</bindings-directory>
<journal-directory>./target/journal</journal-directory>
<journal-min-files>2</journal-min-files>
<large-messages-directory>./target/large-messages</large-messages-directory>
<configuration-file-refresh-period>-1</configuration-file-refresh-period>
<acceptors>
<acceptor name="activemq">tcp://${activemq.remoting.default.host:localhost}:${activemq.remoting.default.port:61616}</acceptor>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
<!--default for catch all-->
<address-setting match="#">
<dead-letter-address>DLQ</dead-letter-address>
<expiry-address>ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10Mb</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>BLOCK</address-full-policy>
</address-setting>
</address-settings>
</core>
</configuration>

View File

@ -413,7 +413,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
config.setConnectionTtlCheckInterval(getLong(e, "connection-ttl-check-interval", config.getConnectionTtlCheckInterval(), Validators.GT_ZERO)); config.setConnectionTtlCheckInterval(getLong(e, "connection-ttl-check-interval", config.getConnectionTtlCheckInterval(), Validators.GT_ZERO));
config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.GT_ZERO)); config.setConfigurationFileRefreshPeriod(getLong(e, "configuration-file-refresh-period", config.getConfigurationFileRefreshPeriod(), Validators.MINUS_ONE_OR_GT_ZERO));
config.setTemporaryQueueNamespace(getString(e, "temporary-queue-namespace", config.getTemporaryQueueNamespace(), Validators.NOT_NULL_OR_EMPTY)); config.setTemporaryQueueNamespace(getString(e, "temporary-queue-namespace", config.getTemporaryQueueNamespace(), Validators.NOT_NULL_OR_EMPTY));

View File

@ -3122,18 +3122,21 @@ public class ActiveMQServerImpl implements ActiveMQServer {
deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration()); deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration());
this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configuration.getConfigurationFileRefreshPeriod()); long configurationFileRefreshPeriod = configuration.getConfigurationFileRefreshPeriod();
if (configurationFileRefreshPeriod > 0) {
this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configurationFileRefreshPeriod);
if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) { if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri)); reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri));
} }
if (System.getProperty("logging.configuration") != null) { if (System.getProperty("logging.configuration") != null) {
try { try {
reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader()); reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader());
} catch (Exception e) { } catch (Exception e) {
// a syntax error with the logging system property shouldn't prevent the server from starting // a syntax error with the logging system property shouldn't prevent the server from starting
ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e); ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e);
}
} }
} }

View File

@ -1,8 +1,8 @@
# Configuration Reload # Configuration Reload
The system will perform a periodic check on the configuration files, configured The system will perform a periodic check on the configuration files, configured
by `configuration-file-refresh-period`, with the default at 5000, in by `configuration-file-refresh-period`, with the default at `5000`, in
milliseconds. milliseconds. These checks can be disabled by specifying `-1`.
Once the configuration file is changed (broker.xml) the following modules will Once the configuration file is changed (broker.xml) the following modules will
be reloaded automatically: be reloaded automatically: