diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java index b2aa2038e9..c9e3833168 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/region/Queue.java @@ -287,8 +287,8 @@ public class Queue extends BaseDestination implements Task { QueueBrowserSubscription browserSubscription = (QueueBrowserSubscription) sub; // do again in iterate to ensure new messages are dispatched - doPageIn(false); - + pageInMessages(false); + synchronized (pagedInMessages) { if (!pagedInMessages.isEmpty()) { BrowserDispatch browserDispatch = new BrowserDispatch(browserSubscription, pagedInMessages.values()); @@ -1339,6 +1339,10 @@ public class Queue extends BaseDestination implements Task { Subscription target = null; int interestCount=0; for (Subscription s : consumers) { + if (s instanceof QueueBrowserSubscription) { + interestCount++; + continue; + } if (dispatchSelector.canSelect(s, node)) { if (!fullConsumers.contains(s)) { if (!s.isFull()) { diff --git a/activemq-core/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java b/activemq-core/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java index d5852f8a0f..7c081aa8cc 100755 --- a/activemq-core/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/JmsQueueBrowserTest.java @@ -95,4 +95,37 @@ public class JmsQueueBrowserTest extends JmsTestSupport { consumer.close(); } + + public void testBrowseReceive() throws Exception { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + ActiveMQQueue destination = new ActiveMQQueue("TEST"); + + connection.start(); + + Message[] outbound = new Message[]{session.createTextMessage("First Message"), + session.createTextMessage("Second Message"), + session.createTextMessage("Third Message")}; + + + MessageProducer producer = session.createProducer(destination); + producer.send(outbound[0]); + + // create browser first + QueueBrowser browser = session.createBrowser((Queue) destination); + Enumeration enumeration = browser.getEnumeration(); + + // create consumer + MessageConsumer consumer = session.createConsumer(destination); + + // browse the first message + assertTrue("should have received the fisrts message", enumeration.hasMoreElements()); + assertEquals(outbound[0], (Message) enumeration.nextElement()); + + // Receive the first message. + assertEquals(outbound[0], consumer.receive(1000)); + consumer.close(); + browser.close(); + producer.close(); + + } }