ARTEMIS-3166 support disabling configuration file reload
This commit is contained in:
parent
5514bca9a6
commit
fea5e246e7
|
@ -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 {
|
||||
Path path = Paths.get(file);
|
||||
Charset charset = StandardCharsets.UTF_8;
|
||||
|
|
|
@ -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>
|
|
@ -413,7 +413,7 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
|
|||
|
||||
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));
|
||||
|
||||
|
|
|
@ -3122,18 +3122,21 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
|
||||
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) {
|
||||
reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri));
|
||||
}
|
||||
if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
|
||||
reloadManager.addCallback(configuration.getConfigurationUrl(), uri -> reloadConfigurationFile(uri));
|
||||
}
|
||||
|
||||
if (System.getProperty("logging.configuration") != null) {
|
||||
try {
|
||||
reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader());
|
||||
} catch (Exception e) {
|
||||
// a syntax error with the logging system property shouldn't prevent the server from starting
|
||||
ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e);
|
||||
if (System.getProperty("logging.configuration") != null) {
|
||||
try {
|
||||
reloadManager.addCallback(new URL(System.getProperty("logging.configuration")), new LoggingConfigurationFileReloader());
|
||||
} catch (Exception e) {
|
||||
// a syntax error with the logging system property shouldn't prevent the server from starting
|
||||
ActiveMQServerLogger.LOGGER.problemAddingConfigReloadCallback(System.getProperty("logging.configuration"), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Configuration Reload
|
||||
|
||||
The system will perform a periodic check on the configuration files, configured
|
||||
by `configuration-file-refresh-period`, with the default at 5000, in
|
||||
milliseconds.
|
||||
by `configuration-file-refresh-period`, with the default at `5000`, in
|
||||
milliseconds. These checks can be disabled by specifying `-1`.
|
||||
|
||||
Once the configuration file is changed (broker.xml) the following modules will
|
||||
be reloaded automatically:
|
||||
|
|
Loading…
Reference in New Issue