Class MQQueueBrowser

java.lang.Object
com.ibm.mq.jms.MQRoot
com.ibm.mq.jms.MQQueueBrowser
All Implemented Interfaces:
JmsPropertyContext, JmsQueueBrowser, JmsReadablePropertyContext, Serializable, AutoCloseable, Map<String,Object>, javax.jms.QueueBrowser

public class MQQueueBrowser extends MQRoot implements javax.jms.QueueBrowser, JmsQueueBrowser
A client uses an MQQueueBrowser to look at messages on a queue without removing them.

Note that the IBM MQ extensions class MQQueueEnumeration is used to hold the browse cursor. This means that each instance of this class will have one open handle to the underlying queue on which the MQQueueBrowser is created. These open queues get closed only when the close() method of MQQueueBrowser is called or when the queue does not have any more messages ( either when MQQueueEnumeration.hasMoreElements() returns false, or MQQueueEnumeration.nextElement() throws a NoSuchElementException ).

See Also:
  • Method Details

    • close

      public void close() throws javax.jms.JMSException
      Closes all open queues left in enumerated objects. Because a provider can allocate some resources outside the JVM on behalf of queue browsers, clients must close them when they are not needed. You cannot rely on garbage collection to reclaim these resources eventually, because this might not occur soon enough.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface javax.jms.QueueBrowser
      Throws:
      javax.jms.JMSException - if JMS fails to close this browser because of a JMS error.
    • getEnumeration

      public Enumeration<?> getEnumeration() throws javax.jms.JMSException
      Gets an enumeration for browsing the current queue messages in the order that they are received.

      If the queue browser detects a poison message, it will not be returned to the enumeration. What happens to the poison message depends upon the IBM MQ messaging provider mode being used by the application:

      Applications using IBM MQ messaging provider normal mode
      --------------------------------------------------------------
      If the MQQueueBrowser was created from an XASession that is taking part in a global transaction and the XASession has not previously been used to perform any transactional work, the message will be left on the queue. In all other cases, the IBM MQ classes for JMS will move the poison message to the backout requeue queue (as specified by the IBM MQ queue parameter BOQNAME) for the queue being browsed.

      Applications using IBM MQ messaging provider migration mode
      -----------------------------------------------------------------
      If the MQQueueBrowser was created from an XASession, the message will be left on the queue. In all other cases, the IBM MQ classes for JMS will move the poison message to the backout requeue queue (as specified by the IBM MQ queue parameter BOQNAME) for the queue being browsed.

      Note that if the browser is created for a nonexistent queue, this is not detected until the first call to this method.

      Specified by:
      getEnumeration in interface javax.jms.QueueBrowser
      Returns:
      an enumeration for browsing the messages.
      Throws:
      javax.jms.JMSException - if JMS fails to get the enumeration for this browser because of a JMS error.
    • getMessageSelector

      public String getMessageSelector() throws javax.jms.JMSException
      Gets the queue browser's message selector expression.
      Specified by:
      getMessageSelector in interface javax.jms.QueueBrowser
      Returns:
      this queue browser's message selector
      Throws:
      javax.jms.JMSException - if JMS fails to get the message selector for this browser due to some JMS error
    • getQueue

      public javax.jms.Queue getQueue() throws javax.jms.JMSException
      Gets an enumeration for browsing the current queue messages in the order that they are received.

      Note that if the browser is created for a nonexistent queue, this is not detected until the first call to getEnumeration().

      Specified by:
      getQueue in interface javax.jms.QueueBrowser
      Returns:
      an enumeration for browsing the messages.
      Throws:
      javax.jms.JMSException - if JMS fails to get the enumeration for this browser because of a JMS error.