You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2021/07/06 19:05:34 UTC

[activemq-artemis] branch main updated: ARTEMIS-3343 log WARN & ignore duplicate address-setting match

This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 47d4b8f  ARTEMIS-3343 log WARN & ignore duplicate address-setting match
     new 3e5795e  This closes #3620
47d4b8f is described below

commit 47d4b8fff441b936cee2a63be27944b93b27e858
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Sun Jul 4 15:59:25 2021 -0500

    ARTEMIS-3343 log WARN & ignore duplicate address-setting match
---
 .../deployers/impl/FileConfigurationParser.java    |  9 +++++--
 .../artemis/core/server/ActiveMQServerLogger.java  |  5 ++++
 .../config/impl/FileConfigurationParserTest.java   |  9 +++++++
 ...onfigurationParser-duplicateAddressSettings.xml | 31 ++++++++++++++++++++++
 4 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
index d93af43..915c2e7 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/deployers/impl/FileConfigurationParser.java
@@ -997,8 +997,13 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
          Element node = (Element) elements.item(0);
          NodeList list = node.getElementsByTagName("address-setting");
          for (int i = 0; i < list.getLength(); i++) {
-            Pair<String, AddressSettings> addressSettings = parseAddressSettings(list.item(i));
-            config.getAddressesSettings().put(addressSettings.getA(), addressSettings.getB());
+            Pair<String, AddressSettings> newAddressSettings = parseAddressSettings(list.item(i));
+            Map<String, AddressSettings> addressSettings = config.getAddressesSettings();
+            if (addressSettings.containsKey(newAddressSettings.getA())) {
+               ActiveMQServerLogger.LOGGER.duplicateAddressSettingMatch(newAddressSettings.getA());
+            } else {
+               config.getAddressesSettings().put(newAddressSettings.getA(), newAddressSettings.getB());
+            }
          }
       }
    }
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
index 59a4917..03add71 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java
@@ -1730,6 +1730,11 @@ public interface ActiveMQServerLogger extends BasicLogger {
       format = Message.Format.MESSAGE_FORMAT)
    void gettingSslHandlerFailed(String clientAddress, String cause);
 
+   @LogMessage(level = Logger.Level.WARN)
+   @Message(id = 222301, value = "Duplicate address-setting match found: {0}. These settings will be ignored! Please review your broker.xml and consolidate any duplicate address-setting elements.",
+      format = Message.Format.MESSAGE_FORMAT)
+   void duplicateAddressSettingMatch(String match);
+
    @LogMessage(level = Logger.Level.ERROR)
    @Message(id = 224000, value = "Failure in initialisation", format = Message.Format.MESSAGE_FORMAT)
    void initializationError(@Cause Throwable e);
diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
index a4b0938..6ee9321 100644
--- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
+++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/FileConfigurationParserTest.java
@@ -38,6 +38,7 @@ import org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.apache.activemq.artemis.utils.ClassloadingUtil;
 import org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec;
 import org.apache.activemq.artemis.utils.PasswordMaskingUtil;
 import org.apache.activemq.artemis.utils.StringPrintStream;
@@ -96,6 +97,14 @@ public class FileConfigurationParserTest extends ActiveMQTestBase {
    }
 
    @Test
+   public void testDuplicateAddressSettings() throws Exception {
+      FileConfigurationParser parser = new FileConfigurationParser();
+      Configuration config = parser.parseMainConfig(ClassloadingUtil.findResource("FileConfigurationParser-duplicateAddressSettings.xml").openStream());
+
+      Assert.assertEquals(123, config.getAddressesSettings().get("foo").getRedistributionDelay());
+   }
+
+   @Test
    public void testParsingClusterConnectionURIs() throws Exception {
       FileConfigurationParser parser = new FileConfigurationParser();
 
diff --git a/artemis-server/src/test/resources/FileConfigurationParser-duplicateAddressSettings.xml b/artemis-server/src/test/resources/FileConfigurationParser-duplicateAddressSettings.xml
new file mode 100644
index 0000000..04619e9
--- /dev/null
+++ b/artemis-server/src/test/resources/FileConfigurationParser-duplicateAddressSettings.xml
@@ -0,0 +1,31 @@
+<!--
+  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"
+               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+               xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
+   <core xmlns="urn:activemq:core">
+      <persistence-enabled>false</persistence-enabled>
+      <address-settings>
+         <address-setting match="foo">
+            <redistribution-delay>123</redistribution-delay>
+         </address-setting>
+         <address-setting match="foo">
+            <redistribution-delay>456</redistribution-delay>
+         </address-setting>
+      </address-settings>
+   </core>
+</configuration>