From 77d1c8cd7f27c846cb0a2ce0efbf97bc12233831 Mon Sep 17 00:00:00 2001 From: gtully Date: Thu, 24 Sep 2020 17:32:01 +0100 Subject: [PATCH] ARTEMIS-2768 - add warning if wildcard subscription does not have a matching page-store-name address setting --- .../core/postoffice/impl/AddressImpl.java | 6 +++- .../core/server/ActiveMQServerLogger.java | 3 ++ .../core/server/impl/ActiveMQServerImpl.java | 8 +++++- .../mqtt/MqttWildCardSubAutoCreateTest.java | 28 +++++++++++++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/AddressImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/AddressImpl.java index 12ef067669..e70fbdb0dd 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/AddressImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/AddressImpl.java @@ -49,7 +49,11 @@ public class AddressImpl implements Address { this.address = address; this.wildcardConfiguration = wildcardConfiguration; addressParts = address.split(wildcardConfiguration.getDelimiter()); - containsWildCard = address.contains(wildcardConfiguration.getSingleWord()) || address.contains(wildcardConfiguration.getAnyWords()); + containsWildCard = isContainsWildCard(address, wildcardConfiguration); + } + + public static boolean isContainsWildCard(SimpleString address, WildcardConfiguration wildcardConfiguration) { + return address.contains(wildcardConfiguration.getSingleWord()) || address.contains(wildcardConfiguration.getAnyWords()); } @Override 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 ac128c41b6..66a9a383d2 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 @@ -1706,6 +1706,9 @@ public interface ActiveMQServerLogger extends BasicLogger { "**************************************************************************************************************************************************************************************************************************************************************", format = Message.Format.MESSAGE_FORMAT) void possibleSplitBrain(String nodeID, String connectionPairInformation); + @LogMessage(level = Logger.Level.WARN) + @Message(id = 222295, value = "Subscription {0} uses wildcard address {1} but no matching address-setting has configured the shared page-store-name; counters may be inaccurate", format = Message.Format.MESSAGE_FORMAT) + void wildcardRoutingWithoutSharedPageStore(SimpleString queueName, SimpleString address); @LogMessage(level = Logger.Level.ERROR) @Message(id = 224000, value = "Failure in initialisation", format = Message.Format.MESSAGE_FORMAT) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index 1c574e16d6..3604435354 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -103,6 +103,7 @@ import org.apache.activemq.artemis.core.postoffice.Binding; import org.apache.activemq.artemis.core.postoffice.BindingType; import org.apache.activemq.artemis.core.postoffice.PostOffice; import org.apache.activemq.artemis.core.postoffice.QueueBinding; +import org.apache.activemq.artemis.core.postoffice.impl.AddressImpl; import org.apache.activemq.artemis.core.postoffice.impl.DivertBinding; import org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding; import org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl; @@ -3512,7 +3513,12 @@ public class ActiveMQServerImpl implements ActiveMQServer { } } - QueueConfigurationUtils.applyDynamicQueueDefaults(queueConfiguration, addressSettingsRepository.getMatch(getRuntimeTempQueueNamespace(queueConfiguration.isTemporary()) + queueConfiguration.getAddress().toString())); + final AddressSettings addressSettings = addressSettingsRepository.getMatch(getRuntimeTempQueueNamespace(queueConfiguration.isTemporary()) + queueConfiguration.getAddress().toString()); + QueueConfigurationUtils.applyDynamicQueueDefaults(queueConfiguration, addressSettings); + + if (AddressImpl.isContainsWildCard(queueConfiguration.getAddress(), configuration.getWildcardConfiguration())) { + ActiveMQServerLogger.LOGGER.wildcardRoutingWithoutSharedPageStore(queueConfiguration.getName(), queueConfiguration.getAddress()); + } AddressInfo info = postOffice.getAddressInfo(queueConfiguration.getAddress()); if (queueConfiguration.isAutoCreateAddress() || queueConfiguration.isTemporary()) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/MqttWildCardSubAutoCreateTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/MqttWildCardSubAutoCreateTest.java index 03a66291ae..09f9110d29 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/MqttWildCardSubAutoCreateTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/mqtt/MqttWildCardSubAutoCreateTest.java @@ -32,6 +32,7 @@ import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.logs.AssertionLoggerHandler; import org.apache.activemq.artemis.tests.integration.mqtt.imported.MQTTTestSupport; import org.apache.activemq.artemis.tests.util.Wait; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; @@ -69,8 +70,8 @@ public class MqttWildCardSubAutoCreateTest extends MQTTTestSupport { @Override protected ActiveMQServer createServer(final boolean realFiles, final Configuration configuration) { - configuration.getAddressesSettings().remove("#"); - configuration.getAddressesSettings().put("#", new AddressSettings().setPageSizeBytes(5).setMaxSizeBytes(10).setPageStoreName(new SimpleString("news-bag"))); + configuration.getAddressesSettings().put("A.#", new AddressSettings().setPageSizeBytes(5).setMaxSizeBytes(10).setPageStoreName(new SimpleString("a-bag"))); + configuration.getAddressesSettings().put("news.#", new AddressSettings().setPageSizeBytes(5).setMaxSizeBytes(10).setPageStoreName(new SimpleString("news-bag"))); configuration.setGlobalMaxSize(15); return createServer(realFiles, configuration, AddressSettings.DEFAULT_PAGE_SIZE, 10); } @@ -231,4 +232,25 @@ public class MqttWildCardSubAutoCreateTest extends MQTTTestSupport { messageWrestlingNews.setStringProperty("stuff", new String(new byte[1024])); } -} + + @Test + public void testWarnOnWildcardWithNoMatchingPageStoreName() throws Exception { + + try { + AssertionLoggerHandler.startCapture(); + + ConnectionFactory cf = new ActiveMQConnectionFactory(); + Connection connection = cf.createConnection(); + connection.setClientID("some-sensible-identity"); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer messageConsumer = session.createDurableConsumer(session.createTopic("b.c.#"), "w-a-warn"); + messageConsumer.close(); + + connection.close(); + Assert.assertTrue(AssertionLoggerHandler.findText("222295")); + } finally { + AssertionLoggerHandler.stopCapture(); + } + } +} \ No newline at end of file