Browsing messages

You can look at messages in a queue without removing them using the QueueBrowser interface. You can browse through all the messages in a queue, or through a subset of the messages. To browse through a queue’s messages, create an instance of a QueueBrowser object using a previously created QueueSession object. To create a browser for viewing all the messages in a queue, call createBrowser and pass the message queue:

javax.jms.QueueBrowser qbrowser =
   queueSession.createBrowser(queue);

To create a browser for viewing a subset of the messages in a queue, call createBrowser and pass the message queue and a message selector string:

javax.jms.QueueBrowser qbrowser =
   queueSession.createBrowser(queue, selector);

For information about message selectors, see “Filtering messages using selectors”.

Once you have access to the QueueBrowser object, call getEnumeration, which returns an Enumeration that allows you to view the messages in the order that they would be received:

java.util.Enumeration enum = qbrowser.getEnumeration();