From 85502a526d2a98dcc926d3b61f114978ee1741c3 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Tue, 15 Nov 2022 10:06:19 -0500 Subject: [PATCH] AMQ-9157 - Dispatched advisory should not fire for queue browsers The dispatched advisory doesn't really make sense to send for queue browsers, just like we don't send a consumed advisory, as it's more of an admin type funtion to look at the contents of a queue but it's not a real consumer that is receiving and acking messages. --- .../apache/activemq/advisory/AdvisoryBroker.java | 3 ++- .../apache/activemq/advisory/AdvisoryTests.java | 16 +++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java b/activemq-broker/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java index 14c8564138..7beb3995de 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java +++ b/activemq-broker/src/main/java/org/apache/activemq/advisory/AdvisoryBroker.java @@ -492,7 +492,8 @@ public class AdvisoryBroker extends BrokerFilter { public void messageDispatched(ConnectionContext context, Subscription sub, MessageReference messageReference) { super.messageDispatched(context, sub, messageReference); try { - if (!messageReference.isAdvisory()) { + //Don't dispatch for queue browsers + if (!messageReference.isAdvisory() && !sub.getConsumerInfo().isBrowser()) { BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination(); ActiveMQTopic topic = AdvisorySupport.getMessageDispatchedAdvisoryTopic(baseDestination.getActiveMQDestination()); Message payload = messageReference.getMessage().copy(); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java index c5faafe3e0..b6866b4b40 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/advisory/AdvisoryTests.java @@ -208,7 +208,7 @@ public class AdvisoryTests { } @Test(timeout = 60000) - public void testQueueBrowserDispatchedAdvisory() throws Exception { + public void testQueueBrowserDispatchedAdvisoryNotSent() throws Exception { Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = s.createQueue(getClass().getName()); @@ -232,19 +232,9 @@ public class AdvisoryTests { assertTrue(enumeration.hasMoreElements()); assertNotNull(enumeration.nextElement()); + //We should not be sending an advisory for dispatching to a browser Message msg = advisoryConsumer.receive(1000); - assertNotNull(msg); - ActiveMQMessage message = (ActiveMQMessage) msg; - ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure(); - - //This should always be tcp:// because that is the transport that is used to connect even though - //the nio transport is the first one in the list - assertTrue(((String)message.getProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL)).startsWith("tcp://")); - assertEquals(message.getProperty(AdvisorySupport.MSG_PROPERTY_DESTINATION), ((ActiveMQDestination) queue).getQualifiedName()); - - //Add assertion to make sure body is included for advisory topics - //when includeBodyForAdvisory is true - assertIncludeBodyForAdvisory(payload); + assertNull(msg); } private void testMessageConsumerAdvisory(ActiveMQDestination dest, Function advisoryTopicSupplier) throws Exception {