Queue browsers

An application uses a queue browser to browse messages on a queue without removing them.

To create a queue browser, an application calls the Create Queue Browser method of an ISession object, specifying as a parameter a Destination object that identifies the queue to be browsed. The application can create a queue browser with or without a message selector.

After creating a queue browser, the application can call the GetEnumerator method of the IQueueBrowser object to get a list of the messages on the queue. The method returns an enumerator that encapsulates a list of Message objects. The order of the Message objects in the list is the same as the order in which the messages would be retrieved from the queue. The application can then use the enumerator to browse each message in turn.

The enumerator is updated dynamically as messages are put on the queue and removed from the queue. Each time the application calls IEnumerator.MoveNext() to browse the next message on the queue, the message reflects the current contents of the queue.

An application can call the GetEnumerator method more than once for a given queue browser. Each call returns a new enumerator. The application can therefore use more than one enumerator to browse the messages on a queue and maintain multiple positions within the queue.

An application can use a queue browser to search for a suitable message to remove from a queue, and then use a message consumer with a message selector to remove the message. The message selector can select the message according to the value of the JMSMessageID header field. For information about this and other JMS message header fields, see Header fields in an XMS message.