com.ibm.mq.jms
Class MQMessageConsumer

java.lang.Object
  |
  +--com.ibm.mq.jms.MQMessageConsumer
All Implemented Interfaces:
javax.jms.MessageConsumer
Direct Known Subclasses:
MQQueueReceiver, MQTopicSubscriber

public class MQMessageConsumer
extends java.lang.Object
implements javax.jms.MessageConsumer

MQMessageConsumer is the parent interface for all message consumers. A client uses a message consumer to receive messages from a Destination.


Method Summary
 void close()
          Closes the message consumer.
 javax.jms.Destination getDestination()
          Gets the message destination.
 javax.jms.MessageListener getMessageListener()
          Gets the message consumer's MessageListener.
 java.lang.String getMessageSelector()
          Gets this message consumer's message selector expression.
 boolean getNoLocal()
          Indicates whether locally published messages are inhibited.
 javax.jms.Message receive()
          Receives the next message produced for this message consumer.
 javax.jms.Message receive(long timeout)
          Receives the next message that arrives within the specified timeout interval.
 javax.jms.Message receiveNoWait()
          Receives the next message if one is immediately available.
 void setMessageListener(javax.jms.MessageListener listener)
          Sets the message consumer's MessageListener.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMessageSelector

public java.lang.String getMessageSelector()
                                    throws javax.jms.JMSException
Gets this message consumer's message selector expression.

Specified by:
getMessageSelector in interface javax.jms.MessageConsumer
Returns:
this message consumer's message selector.
Throws:
javax.jms.JMSException - with reason MQJMS_MESSAGECONSUMER_CLOSED

getNoLocal

public boolean getNoLocal()
                   throws javax.jms.JMSException
Indicates whether locally published messages are inhibited.

Returns:
true means that locally published messages are inhibited.
Throws:
javax.jms.JMSException - with reason MQJMS_MESSAGECONSUMER_CLOSED

setMessageListener

public void setMessageListener(javax.jms.MessageListener listener)
                        throws javax.jms.JMSException
Sets the message consumer's MessageListener.

Specified by:
setMessageListener in interface javax.jms.MessageConsumer
Parameters:
listener - the messages are delivered to this listener.
Throws:
javax.jms.JMSException - with one of the following reasons:
See Also:
MessageConsumer.setMessageListener(javax.jms.MessageListener)

close

public void close()
           throws javax.jms.JMSException
Closes the message consumer. Because a provider can allocate some resources outside the Java Virtual Machine on behalf of a MessageConsumer, 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. This call blocks until a receive() or active message listener has completed.

Specified by:
close in interface javax.jms.MessageConsumer
Throws:
javax.jms.JMSException - with one of the following reasons:

getMessageListener

public javax.jms.MessageListener getMessageListener()
                                             throws javax.jms.JMSException
Gets the message consumer's MessageListener.

Specified by:
getMessageListener in interface javax.jms.MessageConsumer
Returns:
the listener for the message consumer, or null if a listener is not set.
Throws:
javax.jms.JMSException - with reason MQJMS_MESSAGECONSUMER_CLOSED

getDestination

public javax.jms.Destination getDestination()
                                     throws javax.jms.JMSException
Gets the message destination.

Returns:
the destination - either queue or topic.
Throws:
javax.jms.JMSException - with reason MQJMS_MESSAGECONSUMER_CLOSED

receive

public javax.jms.Message receive()
                          throws javax.jms.JMSException
Receives the next message produced for this message consumer.

This call blocks indefinitely until a message is produced or until this message consumer is closed.

If this receive() is done within a transaction, the consumer retains the message until the transaction commits.

Specified by:
receive in interface javax.jms.MessageConsumer
Returns:
the next message produced for this message consumer, or null if this message consumer is concurrently closed
Throws:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to an internal error.

receive

public javax.jms.Message receive(long timeout)
                          throws javax.jms.JMSException
Receives the next message that arrives within the specified timeout interval.

This call blocks until a message arrives, the timeout expires, or this message consumer is closed. A timeout of zero never expires, and the call blocks indefinitely.

Specified by:
receive in interface javax.jms.MessageConsumer
Parameters:
timeout - the timeout value (milliseconds)
Returns:
the next message produced for this message consumer, or null if the timeout expires, or this message consumer is concurrently closed
Throws:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to an internal error.

receiveNoWait

public javax.jms.Message receiveNoWait()
                                throws javax.jms.JMSException
Receives the next message if one is immediately available.

Specified by:
receiveNoWait in interface javax.jms.MessageConsumer
Returns:
the next message produced for this message consumer, or null if one is not available
Throws:
javax.jms.JMSException - if the JMS provider fails to receive the next message due to an internal error.

(c) Copyright IBM Corp. 2005. All Rights Reserved.