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 332e7bdcad..e37fddd82f 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 @@ -501,4 +501,7 @@ public interface ActiveMQMessageBundle { @Message(id = 229234, value = "Invalid slow consumer threshold measurement unit {0}", format = Message.Format.MESSAGE_FORMAT) IllegalArgumentException invalidSlowConsumerThresholdMeasurementUnit(String val); + + @Message(id = 229235, value = "Incompatible binding with name {0} already exists: {1}", format = Message.Format.MESSAGE_FORMAT) + ActiveMQIllegalStateException bindingAlreadyExists(String name, String binding); } 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 c06ac304f4..0dbd005259 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 @@ -3742,12 +3742,16 @@ public class ActiveMQServerImpl implements ActiveMQServer { throw ActiveMQMessageBundle.BUNDLE.invalidQueueName(queueConfiguration.getName()); } - final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueConfiguration.getName()); - if (binding != null) { + final Binding rawBinding = postOffice.getBinding(queueConfiguration.getName()); + if (rawBinding != null) { + if (rawBinding.getType() != BindingType.LOCAL_QUEUE) { + throw ActiveMQMessageBundle.BUNDLE.bindingAlreadyExists(queueConfiguration.getName().toString(), rawBinding.toManagementString()); + } + final QueueBinding queueBinding = (QueueBinding) rawBinding; if (ignoreIfExists) { - return binding.getQueue(); + return queueBinding.getQueue(); } else { - throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueConfiguration.getName(), binding.getAddress()); + throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueConfiguration.getName(), queueBinding.getAddress()); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java index 55dc65bf0d..7fbfddb4f2 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/divert/DivertTest.java @@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; +import org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.QueueConfiguration; @@ -57,6 +58,7 @@ import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.DeletionPolicy; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.tests.util.CFUtil; +import org.apache.activemq.artemis.tests.util.RandomUtil; import org.apache.activemq.command.ActiveMQTopic; import org.junit.Assert; import org.junit.Test; @@ -179,6 +181,27 @@ public class DivertTest extends ActiveMQTestBase { Assert.assertNull(consumer2.receiveImmediate()); } + @Test + public void testDivertAndQueueWithSameName() throws Exception { + final String name = RandomUtil.randomString(); + + ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(createDefaultInVMConfig() + .addDivertConfiguration(new DivertConfiguration() + .setName(name) + .setRoutingName(RandomUtil.randomString()) + .setAddress(RandomUtil.randomString()) + .setForwardingAddress(RandomUtil.randomString())), false)); + + server.start(); + + try { + server.createQueue(new QueueConfiguration(name)); + fail(); + } catch (ActiveMQIllegalStateException e) { + // expected + } + } + @Test public void testCrossProtocol() throws Exception { final String testForConvert = "testConvert";