Browsing messages in a message queue

The JMS queue can contain a number of messages that have not been processed. It is possible to use the QueueBrowser class to examine the contents of a queue. This recipe will build upon the MessageSelectorApplication to illustrate how the QueueBrowser is used.

Getting ready

We will reuse the MessageSelectorApplication as found in the Specifying which types of messages to receive using the message selector recipe.

How to do it...

In the MessageSelectorApplication, modify the PostingServlet to send a "protected" message and to incorporate the QueueBrowser as shown below:

public class PostingServlet extends HttpServlet { @Resource(mappedName="jms/PostingsQueueFactory") private QueueConnectionFactory queueConnectionFactory; ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.