Client applications can use a QueueBrowser to look at messages spooled for a queue without consuming them.
- The delivery restrictions imposed by a queue’s access type (that is, exclusive or non-exclusive) only affect consuming messages from a queue. They do not affect browsing messages on a queue.
- When the client is using Direct Transport mode, a QueueBrowser cannot be used to browse a temporary queue.
For an example of how to browse messages on a queue, refer to the
To browse messages on a queue, do the following:
- Create a
Session.createBrowser(...)and pass in the queue that you want to browse.
Optionally, you can also pass in a selector string for the
Selectorproperty. Using a selector enables the client to only browse messages that match a selector. Note that it could take longer for the message bus to evaluate spooled messages against a selector, especially if the selector used is complex. For more information on selectors, refer to Selectors.
- Use the
QueueBrowserto get an
Enumerationobject that can be used to browse the current queue messages in the order they were received (from oldest to newest) by the queue.
- Iterate over the messages on the queue.
Enumeration.hasMoreElements(). This method returns
trueif there is at least one message available in the browser’s local message buffer; otherwise, it returns
If it returns
false, it does not necessarily mean that the queue is empty, rather the local buffer does not currently contain any messages. Subsequent calls to
trueand return a message, respectively.
: If you want to browse every message on a queue, it is recommended that you use
enumeration.nextElement(). This method keeps returning messages until the local queue is empty and it has not received a message for 10 seconds.
Client applications should not make any assumptions about the polling strategy used by the JMS API when browsing spooled messages. For example, when browsing messages, the JMS API could be requesting more messages from the event broker or returning already buffered messages.
To display the contents of a message in a human‑readable form, you can call
SolJmsUtility.dumpMessage(Message Msg) and pass in the message instance. This method returns a text string that includes JMS message fields and their values along with Solace message fields and their values.
This method is provided as an aid for programmers when developing applications.