Java Reference
In-Depth Information
JMS Queue Browsers
Messages sent to a queue remain in the queue until the message consumer for that queue
consumes them. The JMS API provides a
QueueBrowser
object that allows you to
browse the messages in the queue and display the header values for each message. To
create a
QueueBrowser
object, use the
Session.createBrowser
method. For ex-
ample:
QueueBrowser browser = session.createBrowser(queue);
See “
A Simple Example of Browsing Messages in a Queue
”
on page
394
for an example
of using a
QueueBrowser
object.
The
createBrowser
method allows you to specify a message selector as a second ar-
gument when you create a
QueueBrowser
. For information on message selectors, see
“
JMS Message Selectors
”
on page
355
.
The JMS API provides no mechanism for browsing a topic. Messages usually disappear
from a topic as soon as they appear: If there are no message consumers to consume them,
the JMS provider removes them. Although durable subscriptions allow messages to re-
main on a topic while the message consumer is not active, no facility exists for examining
them.
JMS Exception Handling
The root class for exceptions thrown by JMS API methods is
JMSException
. Catching
JMSException
provides a generic way of handling all exceptions related to the JMS
API.
The
JMSException
class includes the following subclasses, described in the API doc-
umentation:
•
IllegalStateException
•
InvalidClientIDException
•
InvalidDestinationException
•
InvalidSelectorException
•
JMSSecurityException
•
MessageEOFException
•
MessageFormatException
•
MessageNotReadableException