diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java index fdbfbe6aba..cadf14acfe 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java @@ -50,21 +50,25 @@ public class SelectorAwareVirtualTopicInterceptor extends VirtualTopicIntercepto */ @Override protected boolean shouldDispatch(final Broker broker, Message message, Destination dest) throws IOException { - boolean matches = false; - MessageEvaluationContext msgContext = new NonCachedMessageEvaluationContext(); - msgContext.setDestination(dest.getActiveMQDestination()); - msgContext.setMessageReference(message); - List subs = dest.getConsumers(); - for (Subscription sub : subs) { - if (sub.matches(message, msgContext)) { - matches = true; - break; + //first validate that the prefix matches in the super class + if (super.shouldDispatch(broker, message, dest)) { + boolean matches = false; + MessageEvaluationContext msgContext = new NonCachedMessageEvaluationContext(); + msgContext.setDestination(dest.getActiveMQDestination()); + msgContext.setMessageReference(message); + List subs = dest.getConsumers(); + for (Subscription sub : subs) { + if (sub.matches(message, msgContext)) { + matches = true; + break; + } } + if (matches == false) { + matches = tryMatchingCachedSubs(broker, dest, msgContext); + } + return matches; } - if (matches == false) { - matches = tryMatchingCachedSubs(broker, dest, msgContext); - } - return matches; + return false; } private boolean tryMatchingCachedSubs(final Broker broker, Destination dest, MessageEvaluationContext msgContext) { diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopicInterceptor.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopicInterceptor.java index b96171f000..f673770930 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopicInterceptor.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/VirtualTopicInterceptor.java @@ -142,11 +142,8 @@ public class VirtualTopicInterceptor extends DestinationFilter { } protected boolean shouldDispatch(Broker broker, Message message, Destination dest) throws IOException { - //can't find .* in the prefix, so default back to old logic and return true - if(prefix.indexOf(".*")>0){ - return dest.getName().startsWith(prefix.substring(0,prefix.indexOf(".*"))); - } - else return true; + //if can't find .* in the prefix, default back to old logic and return true + return prefix.contains(".*") ? dest.getName().startsWith(prefix.substring(0, prefix.indexOf(".*"))) : true; } protected ActiveMQDestination getQueueConsumersWildcard(ActiveMQDestination original) {