gemmellr commented on code in PR #4502:
URL: https://github.com/apache/activemq-artemis/pull/4502#discussion_r1221351718
##########
artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java:
##########
@@ -928,6 +917,35 @@ private ActiveMQMessageConsumer createConsumer(final
ActiveMQDestination dest,
}
}
+ private SimpleString createFullyQualifedNamedQueue(ActiveMQDestination dest,
+ SimpleString coreFilterString,
+ AddressQuery response) throws
ActiveMQException, JMSException {
+ SimpleString queueName;
+ queueName = CompositeAddress.extractQueueName(dest.getSimpleAddress());
+ if (!response.isExists() ||
!response.getQueueNames().contains(AutoCreateUtil.getCoreQueueName(session,
dest.getSimpleAddress()))) {
+ if (response.isAutoCreateQueues()) {
+ try {
+ createQueue(dest, RoutingType.MULTICAST,
dest.getSimpleAddress(), coreFilterString, true, true, response);
+ } catch (ActiveMQQueueExistsException e) {
+ // The queue was created by another client/admin between the
query check and send create queue packet
Review Comment:
The validation that happens below if the address and queue both exist, would
be entirely skipped in this case if the address or queue didnt exist at query
but did at attempt to create. It seems like it should apply here too though as
its really the exact same situation in terms of 'validate what something else
created'.
##########
artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java:
##########
@@ -928,6 +917,35 @@ private ActiveMQMessageConsumer createConsumer(final
ActiveMQDestination dest,
}
}
+ private SimpleString createFullyQualifedNamedQueue(ActiveMQDestination dest,
+ SimpleString coreFilterString,
+ AddressQuery response) throws
ActiveMQException, JMSException {
+ SimpleString queueName;
+ queueName = CompositeAddress.extractQueueName(dest.getSimpleAddress());
+ if (!response.isExists() ||
!response.getQueueNames().contains(AutoCreateUtil.getCoreQueueName(session,
dest.getSimpleAddress()))) {
+ if (response.isAutoCreateQueues()) {
+ try {
+ createQueue(dest, RoutingType.MULTICAST,
dest.getSimpleAddress(), coreFilterString, true, true, response);
+ } catch (ActiveMQQueueExistsException e) {
+ // The queue was created by another client/admin between the
query check and send create queue packet
+ }
+ } else {
+ throw new InvalidDestinationException("Destination " +
dest.getName() + " does not exist");
+ }
+ } else {
+ QueueQuery queueQuery = session.queueQuery(queueName);
+
+ if (!queueQuery.isExists()) {
+ throw new InvalidDestinationException("Destination " + queueName +
" does not exist");
+ }
+
+ if (coreFilterString != null &&
!queueQuery.getFilterString().equals(coreFilterString)) {
+ throw new JMSException(queueName + " filter mismatch " +
coreFilterString + " is different than " + queueQuery.getFilterString());
Review Comment:
Its not clear (without reading the code) which one is which in the message,
maybe say 'is different than existing queue filter' to clarify.
It might be nice to add something to aid seperating the two filters
visually, e.g use [<filter>] or something, since they could be quite large. Or
quite small; existing clients will be creating queues without any.
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerWithSelector("AMQP", true);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerWithSelector("OPENWIRE", false);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+ testFQQNTopicConsumerWithSelector("CORE", true);
+ }
+
+ private void testFQQNTopicConsumerWithSelector(String protocol, boolean
validateFilterChange) throws Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t, filter);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ org.apache.activemq.artemis.core.server.Queue serverQueue =
server.locateQueue(SimpleString.toSimpleString(queue));
+ Assert.assertNotNull(serverQueue);
+ Assert.assertEquals(RoutingType.MULTICAST,
serverQueue.getRoutingType());
+ Assert.assertNotNull(serverQueue.getFilter());
+ assertEquals(filter,
server.locateQueue(queue).getFilter().getFilterString().toString());
+
+ MessageProducer producer = s.createProducer(s.createTopic("address"));
+ Message message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "value");
+ producer.send(message);
+ Assert.assertNotNull(mc.receive(5000));
+ message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "novalue");
+ producer.send(message);
+ Assert.assertNull(mc.receiveNoWait());
+ }
+
+ if (validateFilterChange) {
Review Comment:
This only validates the case there was an existing filter. Should also
validate 'changing' (adding) filter when there wasnt one (see earlier comments
looking like it could NPE).
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerWithSelector("AMQP", true);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerWithSelector("OPENWIRE", false);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+ testFQQNTopicConsumerWithSelector("CORE", true);
+ }
+
+ private void testFQQNTopicConsumerWithSelector(String protocol, boolean
validateFilterChange) throws Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t, filter);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ org.apache.activemq.artemis.core.server.Queue serverQueue =
server.locateQueue(SimpleString.toSimpleString(queue));
+ Assert.assertNotNull(serverQueue);
+ Assert.assertEquals(RoutingType.MULTICAST,
serverQueue.getRoutingType());
+ Assert.assertNotNull(serverQueue.getFilter());
+ assertEquals(filter,
server.locateQueue(queue).getFilter().getFilterString().toString());
+
+ MessageProducer producer = s.createProducer(s.createTopic("address"));
+ Message message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "value");
+ producer.send(message);
+ Assert.assertNotNull(mc.receive(5000));
+ message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "novalue");
+ producer.send(message);
+ Assert.assertNull(mc.receiveNoWait());
+ }
+
+ if (validateFilterChange) {
+ boolean thrownException = false;
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t,
"shouldThrowException=true");
+ } catch (Exception e) {
+ thrownException = true;
+ }
+ Assert.assertTrue(thrownException);
+ }
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerNoSelector("AMQP");
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerNoSelector("OPENWIRE");
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorCore() throws Exception {
+ testFQQNTopicConsumerNoSelector("CORE");
+ }
+
+ private void testFQQNTopicConsumerNoSelector(String protocol) throws
Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ try (Connection c = factory.createConnection()) {
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ assertNull(server.locateQueue(queue).getFilter());
+ }
+ }
+
+ @Test
+ public void testFQQNTopicConsumerDontExistAMQP() throws Exception {
+ testFQQNTopicConsumerDontExist("AMQP");
+ }
+
+ /* this commented out code is just to make a point that this test would not
be valid in openwire.
+ As openwire is proceeding with creating a topic subscription.
+ Hence there's no need to test this over JMS1.1 with openWire
+ @Test
+ public void testFQQNTopicConsumerDontExistOPENWIRE() throws Exception {
+ testFQQNTopicConsumerDontExist("OPENWIRE");
+ } */
+
+ @Test
+ public void testFQQNTopicConsumerDontExistCORE() throws Exception {
+ testFQQNTopicConsumerDontExist("CORE");
+ }
+
+ private void testFQQNTopicConsumerDontExist(String protocol) throws
Exception {
+ AddressSettings settings = new
AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false);
+ server.getAddressSettingsRepository().clear();
+ server.getAddressSettingsRepository().addMatch("#", settings);
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
+ boolean thrownException = false;
+ try (Connection c = factory.createConnection()) {
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t);
+ } catch (Exception e) {
+ thrownException = true;
+ }
+
+ Assert.assertTrue(thrownException);
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorAMQP() throws Exception {
+ testFQQNQueueConsumerWithSelector("AMQP");
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNQueueConsumerWithSelector("OPENWIRE");
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorCore() throws Exception {
+ testFQQNQueueConsumerWithSelector("CORE");
+ }
+
+ private void testFQQNQueueConsumerWithSelector(String protocol) throws
Exception {
+ AddressSettings settings = new
AddressSettings().setDefaultQueueRoutingType(RoutingType.ANYCAST).setDefaultAddressRoutingType(RoutingType.ANYCAST);
+ server.getAddressSettingsRepository().addMatch("#", settings);
+ final String queue = "myQueue";
+ final String address = "address";
+ final String filter = "prop='inside'";
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String queueQuery = CompositeAddress.toFullyQualified(address, queue)
+ (protocol.equals("OPENWIRE") ? "?selectorAware=true" : "");
+ Queue q = s.createQueue(queueQuery);
+ MessageConsumer mc = s.createConsumer(q, filter);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ org.apache.activemq.artemis.core.server.Queue serverQueue =
server.locateQueue(SimpleString.toSimpleString(queue));
+ Assert.assertEquals(RoutingType.ANYCAST,
serverQueue.getRoutingType());
+ Assert.assertNull(serverQueue.getFilter());
+ MessageProducer p = s.createProducer(q);
+ Message m = s.createMessage();
+ m.setStringProperty("prop", "inside");
+ p.send(m);
+ assertNotNull(mc.receive(1000));
+ m = s.createMessage();
+ m.setStringProperty("prop", RandomUtil.randomString());
+ assertNull(mc.receiveNoWait());
+
+ serverQueue.getConsumers().forEach(queueConsumer -> {
+ Assert.assertNotNull(queueConsumer.getFilter());
Review Comment:
Can it match the actual filter?
To Roman's points, having more than 1 consumer with _different_ filters
would seem useful in this test to verify they are handled correctly. Probably
also sending a message that doesnt match any of them...check it remains,
awaiting some later consumer on the queue.
##########
artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java:
##########
@@ -840,26 +840,15 @@ private ActiveMQMessageConsumer createConsumer(final
ActiveMQDestination dest,
throw new RuntimeException("Subscription name cannot be null
for durable topic consumer");
// Non durable sub
- queueName = new SimpleString(UUID.randomUUID().toString());
- if (!CompositeAddress.isFullyQualified(dest.getAddress())) {
- createTemporaryQueue(dest, RoutingType.MULTICAST, queueName,
coreFilterString, response);
+ if (CompositeAddress.isFullyQualified(dest.getAddress())) {
+ queueName = createFullyQualifedNamedQueue(dest,
coreFilterString, response);
Review Comment:
The createFullyQualifedNamedQueue method name is perhaps a little generic,
would be good to convey that it is currently specific to topic / multicast
address+queue consumers to avoid any confusion later.
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerWithSelector("AMQP", true);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerWithSelector("OPENWIRE", false);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+ testFQQNTopicConsumerWithSelector("CORE", true);
+ }
+
+ private void testFQQNTopicConsumerWithSelector(String protocol, boolean
validateFilterChange) throws Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t, filter);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ org.apache.activemq.artemis.core.server.Queue serverQueue =
server.locateQueue(SimpleString.toSimpleString(queue));
+ Assert.assertNotNull(serverQueue);
+ Assert.assertEquals(RoutingType.MULTICAST,
serverQueue.getRoutingType());
+ Assert.assertNotNull(serverQueue.getFilter());
+ assertEquals(filter,
server.locateQueue(queue).getFilter().getFilterString().toString());
+
+ MessageProducer producer = s.createProducer(s.createTopic("address"));
+ Message message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "value");
+ producer.send(message);
+ Assert.assertNotNull(mc.receive(5000));
+ message = s.createTextMessage("hello");
+ message.setStringProperty("prop", "novalue");
+ producer.send(message);
+ Assert.assertNull(mc.receiveNoWait());
+ }
+
+ if (validateFilterChange) {
+ boolean thrownException = false;
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t,
"shouldThrowException=true");
+ } catch (Exception e) {
+ thrownException = true;
+ }
+ Assert.assertTrue(thrownException);
+ }
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerNoSelector("AMQP");
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerNoSelector("OPENWIRE");
+ }
+
+ @Test
+ public void testFQQNTopicConsumerNoSelectorCore() throws Exception {
+ testFQQNTopicConsumerNoSelector("CORE");
+ }
+
+ private void testFQQNTopicConsumerNoSelector(String protocol) throws
Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ try (Connection c = factory.createConnection()) {
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ assertNull(server.locateQueue(queue).getFilter());
+ }
+ }
+
+ @Test
+ public void testFQQNTopicConsumerDontExistAMQP() throws Exception {
+ testFQQNTopicConsumerDontExist("AMQP");
+ }
+
+ /* this commented out code is just to make a point that this test would not
be valid in openwire.
+ As openwire is proceeding with creating a topic subscription.
+ Hence there's no need to test this over JMS1.1 with openWire
+ @Test
+ public void testFQQNTopicConsumerDontExistOPENWIRE() throws Exception {
+ testFQQNTopicConsumerDontExist("OPENWIRE");
+ } */
+
+ @Test
+ public void testFQQNTopicConsumerDontExistCORE() throws Exception {
+ testFQQNTopicConsumerDontExist("CORE");
+ }
+
+ private void testFQQNTopicConsumerDontExist(String protocol) throws
Exception {
+ AddressSettings settings = new
AddressSettings().setAutoCreateAddresses(false).setAutoCreateQueues(false);
+ server.getAddressSettingsRepository().clear();
+ server.getAddressSettingsRepository().addMatch("#", settings);
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
+ boolean thrownException = false;
+ try (Connection c = factory.createConnection()) {
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Topic t = s.createTopic(CompositeAddress.toFullyQualified(address,
queue));
+ MessageConsumer mc = s.createConsumer(t);
+ } catch (Exception e) {
+ thrownException = true;
+ }
+
+ Assert.assertTrue(thrownException);
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorAMQP() throws Exception {
+ testFQQNQueueConsumerWithSelector("AMQP");
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNQueueConsumerWithSelector("OPENWIRE");
+ }
+
+ @Test
+ public void testFQQNQueueConsumerWithSelectorCore() throws Exception {
+ testFQQNQueueConsumerWithSelector("CORE");
+ }
+
+ private void testFQQNQueueConsumerWithSelector(String protocol) throws
Exception {
+ AddressSettings settings = new
AddressSettings().setDefaultQueueRoutingType(RoutingType.ANYCAST).setDefaultAddressRoutingType(RoutingType.ANYCAST);
+ server.getAddressSettingsRepository().addMatch("#", settings);
+ final String queue = "myQueue";
+ final String address = "address";
+ final String filter = "prop='inside'";
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ try (Connection c = factory.createConnection()) {
+ c.start();
+ Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String queueQuery = CompositeAddress.toFullyQualified(address, queue)
+ (protocol.equals("OPENWIRE") ? "?selectorAware=true" : "");
+ Queue q = s.createQueue(queueQuery);
+ MessageConsumer mc = s.createConsumer(q, filter);
+ Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+ org.apache.activemq.artemis.core.server.Queue serverQueue =
server.locateQueue(SimpleString.toSimpleString(queue));
+ Assert.assertEquals(RoutingType.ANYCAST,
serverQueue.getRoutingType());
+ Assert.assertNull(serverQueue.getFilter());
+ MessageProducer p = s.createProducer(q);
+ Message m = s.createMessage();
+ m.setStringProperty("prop", "inside");
+ p.send(m);
+ assertNotNull(mc.receive(1000));
+ m = s.createMessage();
+ m.setStringProperty("prop", RandomUtil.randomString());
+ assertNull(mc.receiveNoWait());
Review Comment:
Some newlines to group separate 'steps' would make this more readable.
##########
artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java:
##########
@@ -928,6 +917,35 @@ private ActiveMQMessageConsumer createConsumer(final
ActiveMQDestination dest,
}
}
+ private SimpleString createFullyQualifedNamedQueue(ActiveMQDestination dest,
+ SimpleString coreFilterString,
+ AddressQuery response) throws
ActiveMQException, JMSException {
+ SimpleString queueName;
+ queueName = CompositeAddress.extractQueueName(dest.getSimpleAddress());
+ if (!response.isExists() ||
!response.getQueueNames().contains(AutoCreateUtil.getCoreQueueName(session,
dest.getSimpleAddress()))) {
+ if (response.isAutoCreateQueues()) {
+ try {
+ createQueue(dest, RoutingType.MULTICAST,
dest.getSimpleAddress(), coreFilterString, true, true, response);
+ } catch (ActiveMQQueueExistsException e) {
+ // The queue was created by another client/admin between the
query check and send create queue packet
+ }
+ } else {
+ throw new InvalidDestinationException("Destination " +
dest.getName() + " does not exist");
+ }
+ } else {
+ QueueQuery queueQuery = session.queueQuery(queueName);
+
+ if (!queueQuery.isExists()) {
+ throw new InvalidDestinationException("Destination " + queueName +
" does not exist");
+ }
+
+ if (coreFilterString != null &&
!queueQuery.getFilterString().equals(coreFilterString)) {
Review Comment:
The second leg seems like it can NPE as nothing says
queueQuery.getFilterString() will return a non-null value, and part of this
change is specifically adressing that existing Core clients or the broker didnt
add any filter to the queue..so I'd expect that to result in a null currently
already. Could just flip the order of the second check, to
coreFilterString.equals(..) since that was just null checked.
There is a question for me over whether it should do this check for an FQQN
though....plus its also not doing the reverse-check, i.e if the queue exists
with a filter but the consumer doesnt have a filter, thats allowed/ignored. I
might consider just to document that mismatches with FQQN requires queue
deletion/recreation if it isnt what you wanted.
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerWithSelector("AMQP", true);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerWithSelector("OPENWIRE", false);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+ testFQQNTopicConsumerWithSelector("CORE", true);
+ }
+
+ private void testFQQNTopicConsumerWithSelector(String protocol, boolean
validateFilterChange) throws Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
Review Comment:
Having a couple of different 'fake sub FQQN queues' on the same address,
with different filters, to validate they are both handled correctly would seem
good for this test. Send messages that match one, the other, both, and neither
filter and verify handling.
##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+package org.apache.activemq.artemis.tests.integration.jms.multiprotocol;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+ testFQQNTopicConsumerWithSelector("AMQP", true);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+ testFQQNTopicConsumerWithSelector("OPENWIRE", false);
+ }
+
+ @Test
+ public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+ testFQQNTopicConsumerWithSelector("CORE", true);
+ }
+
+ private void testFQQNTopicConsumerWithSelector(String protocol, boolean
validateFilterChange) throws Exception {
+ ConnectionFactory factory = CFUtil.createConnectionFactory(protocol,
"tcp://localhost:5672");
+ final String queue = "queue";
+ final String address = "address";
+ final String filter = "prop='value'";
Review Comment:
Using e.g 'match' and 'mismatch' would be more readable than having value of
'value' and 'novalue'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]