You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "gemmellr (via GitHub)" <gi...@apache.org> on 2023/05/02 11:18:52 UTC

[GitHub] [activemq-artemis] gemmellr commented on a diff in pull request #4452: ARTEMIS-4259 JMS consumer + FQQN + selector not working

gemmellr commented on code in PR #4452:
URL: https://github.com/apache/activemq-artemis/pull/4452#discussion_r1182386483


##########
artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java:
##########
@@ -848,7 +848,7 @@ private ActiveMQMessageConsumer createConsumer(final ActiveMQDestination dest,
                   if (!response.isExists() || !response.getQueueNames().contains(AutoCreateUtil.getCoreQueueName(session, dest.getSimpleAddress()))) {
                      if (response.isAutoCreateQueues()) {
                         try {
-                           createQueue(dest, RoutingType.MULTICAST, dest.getSimpleAddress(), null, true, true, response);
+                           createQueue(dest, RoutingType.MULTICAST, dest.getSimpleAddress(), coreFilterString, true, true, response);

Review Comment:
   This only auto-creates the queue with the expected filter, if it doesnt already exist. The consumer itself (11 lines down) still has no filter. As such it will continue to erroneously consume invalid/non-matching messages for the applications specified filter, if they happen to exist on the queue. Say, either because the application has changed their filter from what the queue was created with previously, or because the queue exists without any filter at all (e.g, created by a current/previous client version that ignores the filter).
   
   The consumer should be filtered such that it only ever gets messages matching the filter used by the appliation.



##########
tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/multiprotocol/JMSFQQNConsumerTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.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.utils.CompositeAddress;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.junit.Test;
+
+public class JMSFQQNConsumerTest extends MultiprotocolJMSClientTestSupport {
+
+   @Test
+   public void testFQQNTopicConsumerWithSelectorAMQP() throws Exception {
+      testFQQNTopicConsumerWithSelector(AMQPConnection);
+   }
+
+   @Test
+   public void testFQQNTopicConsumerWithSelectorOpenWire() throws Exception {
+      testFQQNTopicConsumerWithSelector(OpenWireConnection);
+   }
+
+   @Test
+   public void testFQQNTopicConsumerWithSelectorCore() throws Exception {
+      testFQQNTopicConsumerWithSelector(CoreConnection);
+   }
+
+   private void testFQQNTopicConsumerWithSelector(ConnectionSupplier supplier) throws Exception {
+      final String queue = "queue";
+      final String address = "address";
+      final String filter = "prop='value'";
+      try (Connection c = supplier.createConnection()) {
+         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);
+         assertNotNull(server.locateQueue(queue).getFilter());
+         assertEquals(filter, server.locateQueue(queue).getFilter().getFilterString().toString());
+      }
+   }
+
+   @Test
+   public void testFQQNQueueConsumerWithSelectorAMQP() throws Exception {
+      testFQQNQueueConsumerWithSelector(AMQPConnection);
+   }
+
+   @Test
+   public void testFQQNQueueConsumerWithSelectorOpenWire() throws Exception {
+      testFQQNQueueConsumerWithSelector(OpenWireConnection);
+   }
+
+   @Test
+   public void testFQQNQueueConsumerWithSelectorCore() throws Exception {
+      testFQQNQueueConsumerWithSelector(CoreConnection);
+   }
+
+   private void testFQQNQueueConsumerWithSelector(ConnectionSupplier supplier) throws Exception {
+      final String queue = "queue";
+      final String address = "address";
+      final String prop = "prop";
+      final String value = RandomUtil.randomString();
+      final String filter = prop + "='" + value + "'";
+      try (Connection c = supplier.createConnection()) {
+         Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue q = s.createQueue(CompositeAddress.toFullyQualified(address, queue));
+         MessageConsumer mc = s.createConsumer(q, filter);
+         Wait.assertTrue(() -> server.locateQueue(queue) != null, 2000, 100);
+         assertNull(server.locateQueue(queue).getFilter());
+         MessageProducer p = s.createProducer(q);
+         Message m = s.createMessage();
+         m.setStringProperty(prop, value);
+         p.send(m);
+         c.start();
+         assertNotNull(mc.receive(1000));
+         m = s.createMessage();
+         m.setStringProperty(prop, RandomUtil.randomString());
+         assertNull(mc.receive(1000));

Review Comment:
   The second creation+prop-set for 'm' seems unused since all it does after is cehck nothing is received.
   
   Some separation would help readability, perhaps make things like that more obvious.



-- 
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: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org