ARTEMIS-2768 - add warning if wildcard subscription does not have a matching page-store-name address setting

This commit is contained in:
gtully 2020-09-24 17:32:01 +01:00 committed by Clebert Suconic
parent 9c9cef33c8
commit 77d1c8cd7f
4 changed files with 40 additions and 5 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()) {

View File

@ -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();
}
}
}