Examining a Queue
A QueueBrowser is a specialized
object that allows you to peek ahead at pending messages on a Queue without actually consuming them. This
feature is unique to point-to-point messaging. Queue browsing can be
useful for monitoring the contents of a queue from an administration
tool or for browsing through multiple messages to locate a message that
is more important than the one at the head of the queue. It is also
useful for other monitoring tasks, such as determining the current queue
depth.
Messages obtained from a QueueBrowser are copies of messages contained
in the queue and are not considered to be consumed—they are merely for
browsing. It is also important to
note that the QueueBrowser is not
guaranteed to have a definitive list of messages in the queue. The QueueBrowser contains only a snapshot, or a
copy of, the queue as it appears at the time the QueueBrowser is created. The contents of the
queue may change between the time the browser is created and the time
you examine its contents. However, no matter how small that window of
time is, new messages may arrive and other messages may be consumed by
other JMS clients.
A QueueBrowser is created from
the Session object using the createBrowser() method. This method takes as
an argument the queue from which you would like to view the messages. It
is during the createBrowser() method
invocation that the snapshot is taken from the queue. You can then get a
list of the messages by using the method getEnumeration() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access