diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java index 2bd5db3a36..f502d00dda 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java @@ -121,8 +121,8 @@ public interface ActiveMQMessageBundle { @Message(id = 119018, value = "Binding already exists {0}", format = Message.Format.MESSAGE_FORMAT) ActiveMQQueueExistsException bindingAlreadyExists(Binding binding); - @Message(id = 119019, value = "Queue already exists {0}", format = Message.Format.MESSAGE_FORMAT) - ActiveMQQueueExistsException queueAlreadyExists(SimpleString queueName); + @Message(id = 119019, value = "Queue {0} already exists on address {1}", format = Message.Format.MESSAGE_FORMAT) + ActiveMQQueueExistsException queueAlreadyExists(SimpleString queueName, SimpleString addressName); @Message(id = 119020, value = "Invalid filter: {0}", format = Message.Format.MESSAGE_FORMAT) ActiveMQInvalidFilterExpressionException invalidFilter(@Cause Throwable e, SimpleString filter); 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 65e368ccf9..2ff784cca1 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 @@ -94,8 +94,8 @@ public interface ActiveMQServerLogger extends BasicLogger { void serverStopped(String version, SimpleString nodeId, String uptime); @LogMessage(level = Logger.Level.INFO) - @Message(id = 221003, value = "Deploying queue {0}", format = Message.Format.MESSAGE_FORMAT) - void deployQueue(SimpleString queueName); + @Message(id = 221003, value = "Deploying queue {0} on address {1}", format = Message.Format.MESSAGE_FORMAT) + void deployQueue(String queueName, String addressName); @LogMessage(level = Logger.Level.INFO) @Message(id = 221004, value = "{0}", 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 d58799e40e..db0a25987e 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 @@ -49,6 +49,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; +import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy; import org.apache.activemq.artemis.api.core.ActiveMQDeleteAddressException; import org.apache.activemq.artemis.api.core.ActiveMQException; @@ -2511,20 +2512,24 @@ public class ActiveMQServerImpl implements ActiveMQServer { private void deployQueuesFromListCoreQueueConfiguration(List queues) throws Exception { for (CoreQueueConfiguration config : queues) { - addOrUpdateQueue(config); - } - } + SimpleString queueName = SimpleString.toSimpleString(config.getName()); + ActiveMQServerLogger.LOGGER.deployQueue(config.getName(), config.getAddress()); - private Queue addOrUpdateQueue(CoreQueueConfiguration config) throws Exception { - SimpleString queueName = SimpleString.toSimpleString(config.getName()); - ActiveMQServerLogger.LOGGER.deployQueue(queueName); - Queue queue = updateQueue(config.getName(), config.getRoutingType(), config.getMaxConsumers(), config.getPurgeOnNoConsumers()); - if (queue == null) { - queue = createQueue(SimpleString.toSimpleString(config.getAddress()), config.getRoutingType(), - queueName, SimpleString.toSimpleString(config.getFilterString()), null, - config.isDurable(), false, true, false, false, config.getMaxConsumers(), config.getPurgeOnNoConsumers(), true); + // determine if there is an address::queue match; update it if so + if (locateQueue(queueName) != null && locateQueue(queueName).getAddress().toString().equals(config.getAddress())) { + updateQueue(config.getName(), config.getRoutingType(), config.getMaxConsumers(), config.getPurgeOnNoConsumers()); + } else { + // if the address::queue doesn't exist then create it + try { + createQueue(SimpleString.toSimpleString(config.getAddress()), config.getRoutingType(), + queueName, SimpleString.toSimpleString(config.getFilterString()),null, + config.isDurable(),false,false,false,false,config.getMaxConsumers(),config.getPurgeOnNoConsumers(),true); + } catch (ActiveMQQueueExistsException e) { + // the queue may exist on a *different* address + ActiveMQServerLogger.LOGGER.warn(e.getMessage()); + } + } } - return queue; } private void deployQueuesFromConfiguration() throws Exception { @@ -2701,7 +2706,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { if (ignoreIfExists) { return binding.getQueue(); } else { - throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName); + throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName, binding.getAddress()); } } 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 0ce67db58c..01f23e205c 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 @@ -22,12 +22,14 @@ import java.util.HashMap; import java.util.Map; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.FileDeploymentManager; import org.apache.activemq.artemis.core.config.HAPolicyConfiguration; import org.apache.activemq.artemis.core.config.WildcardConfiguration; import org.apache.activemq.artemis.core.config.ha.SharedStoreMasterPolicyConfiguration; import org.apache.activemq.artemis.core.deployers.impl.FileConfigurationParser; +import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec; import org.junit.Assert; @@ -72,6 +74,18 @@ public class FileConfigurationParserTest extends ActiveMQTestBase { deploymentManager.readConfiguration(); } + @Test + public void testDuplicateQueue() throws Exception { + String filename = "duplicateQueue.xml"; + FileConfiguration fc = new FileConfiguration(); + FileDeploymentManager deploymentManager = new FileDeploymentManager(filename); + deploymentManager.addDeployable(fc); + deploymentManager.readConfiguration(); + ActiveMQServer server = addServer((ActiveMQServer) deploymentManager.buildService(null, null).get("core")); + server.start(); + assertEquals(0, server.locateQueue(SimpleString.toSimpleString("q")).getMaxConsumers()); + } + @Test public void testParsingClusterConnectionURIs() throws Exception { FileConfigurationParser parser = new FileConfigurationParser(); diff --git a/artemis-server/src/test/resources/duplicateQueue.xml b/artemis-server/src/test/resources/duplicateQueue.xml new file mode 100644 index 0000000000..11f18931a9 --- /dev/null +++ b/artemis-server/src/test/resources/duplicateQueue.xml @@ -0,0 +1,35 @@ + + + + + +
+ + + +
+
+ + + +
+
+
+