Skip to content

Commit 51b5e19

Browse files
committed
ARTEMIS-5588 allow config reload when there is no xml, just property files
1 parent 3384d54 commit 51b5e19

2 files changed

Lines changed: 75 additions & 19 deletions

File tree

artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,21 +3385,22 @@ synchronized boolean initialisePart1(boolean scalingDown) throws Exception {
33853385
if (configurationFileRefreshPeriod > 0) {
33863386
this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configurationFileRefreshPeriod);
33873387

3388-
if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
3389-
final URL configUrl = configuration.getConfigurationUrl();
3390-
ReloadCallback xmlConfigReload = uri -> {
3391-
// ignore the argument from the callback such that we can respond
3392-
// to property file locations with a full reload
3393-
reloadConfigurationFile(configUrl);
3394-
};
3395-
reloadManager.addCallback(configUrl, xmlConfigReload);
3396-
3397-
// watch properties and reload xml config
3398-
String propsLocations = configuration.resolvePropertiesSources(propertiesFileUrl);
3399-
if (propsLocations != null) {
3400-
for (String fileUrl : propsLocations.split(",")) {
3401-
reloadManager.addCallback(new File(fileUrl).toURI().toURL(), xmlConfigReload);
3402-
}
3388+
final URL configUrl = configuration.getConfigurationUrl();
3389+
ReloadCallback fullConfigReloadCallback = uri -> {
3390+
// ignore the argument from the callback such that we can respond
3391+
// to property file locations with a full reload
3392+
reloadConfigurationFile(configUrl);
3393+
};
3394+
3395+
if (configUrl != null) {
3396+
reloadManager.addCallback(configUrl, fullConfigReloadCallback);
3397+
}
3398+
3399+
// watch properties and reload config
3400+
String propsLocations = configuration.resolvePropertiesSources(propertiesFileUrl);
3401+
if (propsLocations != null) {
3402+
for (String fileUrl : propsLocations.split(",")) {
3403+
reloadManager.addCallback(new File(fileUrl).toURI().toURL(), fullConfigReloadCallback);
34033404
}
34043405
}
34053406

@@ -4624,9 +4625,14 @@ public void reloadConfigurationFile() throws Exception {
46244625
}
46254626

46264627
private void reloadConfigurationFile(URL uri) throws Exception {
4627-
Configuration config = new FileConfigurationParser().parseMainConfig(uri.openStream());
4628-
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(config);
4629-
legacyJMSConfiguration.parseConfiguration(uri.openStream());
4628+
Configuration config = null;
4629+
if (uri == null) {
4630+
config = new ConfigurationImpl();
4631+
} else {
4632+
config = new FileConfigurationParser().parseMainConfig(uri.openStream());
4633+
LegacyJMSConfiguration legacyJMSConfiguration = new LegacyJMSConfiguration(config);
4634+
legacyJMSConfiguration.parseConfiguration(uri.openStream());
4635+
}
46304636
configuration.setSecurityRoles(config.getSecurityRoles());
46314637
configuration.setAddressSettings(config.getAddressSettings());
46324638
configuration.setDivertConfigurations(config.getDivertConfigurations());

tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/server/ConfigurationTest.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.io.File;
2424
import java.io.FileOutputStream;
25+
import java.util.Properties;
2526

2627
import org.apache.activemq.artemis.api.core.SimpleString;
2728
import org.apache.activemq.artemis.core.config.CoreQueueConfiguration;
@@ -82,7 +83,7 @@ public void testPropertiesConfigReload() throws Exception {
8283
propsFile.createNewFile();
8384

8485
ConfigurationImpl.InsertionOrderedProperties config = new ConfigurationImpl.InsertionOrderedProperties();
85-
config.put("configurationFileRefreshPeriod", "500");
86+
config.put("configurationFileRefreshPeriod", "100");
8687

8788
config.put("addressConfigurations.mytopic_3.routingTypes", "MULTICAST");
8889

@@ -161,6 +162,55 @@ public void testPropertiesConfigReload() throws Exception {
161162
}
162163
}
163164

165+
@Test
166+
public void testPropertiesOnlyConfigReload() throws Exception {
167+
168+
File propsFile = new File(getTestDirfile(), "somemore.props");
169+
propsFile.createNewFile();
170+
171+
172+
Properties properties = new ConfigurationImpl.InsertionOrderedProperties();
173+
properties.put("configurationFileRefreshPeriod", "100");
174+
properties.put("persistenceEnabled", "false");
175+
properties.put("connectionRouters.joe.localTargetFilter", "LF");
176+
177+
try (FileOutputStream outStream = new FileOutputStream(propsFile)) {
178+
properties.store(outStream, null);
179+
}
180+
assertTrue(propsFile.exists());
181+
182+
FileConfiguration fc = new FileConfiguration();
183+
ActiveMQJAASSecurityManager sm = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
184+
ActiveMQServer server = addServer(new ActiveMQServerImpl(fc, sm));
185+
server.setProperties(propsFile.getAbsolutePath()); // no xml config
186+
try {
187+
188+
server.start();
189+
190+
assertEquals(1, server.getConfiguration().getConnectionRouters().size());
191+
assertEquals("LF", server.getConfiguration().getConnectionRouters().get(0).getLocalTargetFilter());
192+
193+
properties.put("persistenceEnabled", "false");
194+
properties.put("configurationFileRefreshPeriod", "100");
195+
196+
// verify update
197+
properties.put("connectionRouters.joe.localTargetFilter", "UPDATED");
198+
try (FileOutputStream outStream = new FileOutputStream(propsFile)) {
199+
properties.store(outStream, null);
200+
}
201+
202+
Wait.assertTrue(() -> {
203+
return "UPDATED".equals(server.getConfiguration().getConnectionRouters().get(0).getLocalTargetFilter());
204+
});
205+
206+
} finally {
207+
try {
208+
server.stop();
209+
} catch (Exception e) {
210+
}
211+
}
212+
}
213+
164214
protected ActiveMQServer getActiveMQServer(String brokerConfig) throws Exception {
165215
FileConfiguration fc = new FileConfiguration();
166216
FileJMSConfiguration fileConfiguration = new FileJMSConfiguration();

0 commit comments

Comments
 (0)