activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r473219 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/Queue.java test/java/org/apache/activemq/JMSExclusiveConsumerTest.java
Date Fri, 10 Nov 2006 07:16:25 GMT
Author: aco
Date: Thu Nov  9 23:16:25 2006
New Revision: 473219

URL: http://svn.apache.org/viewvc?view=rev&rev=473219
Log:
https://issues.apache.org/activemq/browse/AMQ-1024
- Fix case where a non-exclusive consumer registered first will receive a message, before
an exclusive consumer.
- Added junit test case to demonstrate the issue.

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java?view=diff&rev=473219&r1=473218&r2=473219
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java
Thu Nov  9 23:16:25 2006
@@ -160,7 +160,12 @@
         MessageEvaluationContext msgContext = context.getMessageEvaluationContext();
         try {
             synchronized (consumers) {
-                consumers.add(sub);
+                if (sub.getConsumerInfo().isExclusive()) {
+                    // Add to front of list to ensure that an exclusive consumer gets all
messages
+                    // before non-exclusive consumers
+                    consumers.add(0, sub);
+                } else {
+                    consumers.add(sub);
             }
 
             highestSubscriptionPriority = calcHighestSubscriptionPriority();

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java?view=diff&rev=473219&r1=473218&r2=473219
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/JMSExclusiveConsumerTest.java
Thu Nov  9 23:16:25 2006
@@ -128,4 +128,29 @@
         assertNull(consumer1.receiveNoWait());
         assertNull(consumer2.receiveNoWait());
     }
+
+    public void testMixExclusiveWithNonExclusive() throws Exception {
+        ActiveMQQueue exclusiveQueue = new ActiveMQQueue("TEST.FOO?consumer.exclusive=true");
+        ActiveMQQueue nonExclusiveQueue = new ActiveMQQueue("TEST.FOO?consumer.exclusive=false");
+
+        connection.start();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        MessageConsumer nonExCon = session.createConsumer(nonExclusiveQueue);
+        MessageConsumer exCon = session.createConsumer(exclusiveQueue);
+
+
+        MessageProducer prod = session.createProducer(exclusiveQueue);
+        prod.send(session.createMessage());
+        prod.send(session.createMessage());
+        prod.send(session.createMessage());
+
+        Message m;
+        for (int i=0; i<3; i++) {
+            m = exCon.receive(1000);
+            assertNotNull(m);
+            m = nonExCon.receive(1000);
+            assertNull(m);
+        }
+    }
 }



Mime
View raw message