Websphere MQ Everyplace

com.ibm.mqe.jms
Class MQeMessageConsumer

java.lang.Object
  |
  +--com.ibm.mqe.jms.MQeMessageConsumer
All Implemented Interfaces:
javax.jms.MessageConsumer
Direct Known Subclasses:
MQeQueueReceiver

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

A client uses a message consumer to receive messages from a Destination. A MessageConsumer object is created by passing a Destination object to a message-consumer creation method supplied by a session.

A message consumer can be created with a message selector. This allows the client to restrict the messages delivered to the message consumer to those that match the selector.

A client may either synchronously receive a message consumer's messages or have the consumer asynchronously deliver them as they arrive.

For synchronous receipt, a client can request the next message from a message consumer using one of its receive methods. There are several variations of receive that allow a client to poll or wait for the next message.

For asynchronous delivery, a client can register a MessageListener object with a message consumer. As messages arrive at the message consumer, it delivers them by calling the MessageListener's onMessage method.

It is a client programming error for a MessageListener to throw an exception.

See Also:
QueueReceiver

Constructor Summary
MQeMessageConsumer()
           
 
Method Summary
 void close()
          Since a provider may allocate some resources on behalf of a MessageConsumer outside the JVM, clients should close them when they are not needed.
 javax.jms.MessageListener getMessageListener()
          Gets the message consumer's MessageListener.
 java.lang.String getMessageSelector()
          Gets this message consumer's message selector expression.
 javax.jms.Message receive()
          Receive the next message produced for this message consumer.
 javax.jms.Message receive(long timeOut)
          Receive the next message that arrives within the specified timeout interval.
 javax.jms.Message receiveNoWait()
          Receive the next message if one is immediately available.
 void setMessageListener(javax.jms.MessageListener newListener)
          Set the message consumer's MessageListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MQeMessageConsumer

public MQeMessageConsumer()
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, or null if no message selector exists for the message consumer (that is, if the message selector was not set or was set to null or the empty string)
Throws:
javax.jms.JMSException - if the JMS provider fails to get the message selector due to some internal error.

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 no listener is set
Throws:
javax.jms.JMSException - if the JMS provider fails to get the message listener due to some internal error.
See Also:
MessageConsumer.setMessageListener(javax.jms.MessageListener)

setMessageListener

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

Specified by:
setMessageListener in interface javax.jms.MessageConsumer
Throws:
javax.jms.JMSException - if JMS fails to set message listener due to some JMS error
See Also:
MessageConsumer.getMessageListener()

receive

public javax.jms.Message receive()
                          throws javax.jms.JMSException
Receive the next message produced for this message consumer. This call blocks indefinitely until a message is produced.

Specified by:
receive in interface javax.jms.MessageConsumer
Returns:
the next message produced for this message consumer.
Throws:
javax.jms.JMSException - if JMS fails to receive the next message due to some error.

receive

public javax.jms.Message receive(long timeOut)
                          throws javax.jms.JMSException
Receive the next message that arrives within the specified timeout interval. This call blocks until either a message arrives or the timeout expires.

Specified by:
receive 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 JMS fails to receive the next message due to some error.

receiveNoWait

public javax.jms.Message receiveNoWait()
                                throws javax.jms.JMSException
Receive 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 JMS fails to receive the next message due to some error.

close

public void close()
           throws javax.jms.JMSException
Since a provider may allocate some resources on behalf of a MessageConsumer outside the JVM, clients should close them when they are not needed. Relying on garbage collection to eventually reclaim these resources may not be timely enough.

Specified by:
close in interface javax.jms.MessageConsumer
Throws:
javax.jms.JMSException - if JMS fails to close the consumer due to some error.

Websphere MQ Everyplace