MessageConsumer
public interface MessageConsumer
Subinterfaces: QueueReceiver and TopicSubscriber
WebSphere MQ class: MQMessageConsumer
java.lang.Object | +----com.ibm.mq.jms.MQMessageConsumerMessageConsumer is the parent interface for all message consumers.
A client uses a message consumer to receive messages from a Destination.
Methods
- getMessageListener
public MessageListener getMessageListener() throws JMSException
Get the message consumer's MessageListener.
- Returns:
- The listener for the message consumer, or null if a listener is not set.
- Throws:
- JMSException if JMS fails to get the message listener because of a JMS error.
- See also:
- setMessageListener
- getMessageSelector
public java.lang.String getMessageSelector() throws JMSException
Get this message consumer's message selector expression.
- Returns:
- The message consumer's message selector.
- Throws:
- JMSException if JMS fails to get the message selector because of a JMS error.
- receive
public Message receive() throws JMSException
Receive the next message produced for this message consumer.
- Returns:
- The next message produced for this message consumer.
- Throws:
- JMSException if JMS fails to receive the next message because of an error.
- receive
public Message receive(long timeOut) throws JMSException
Receive the next message that arrives within the specified timeout interval. A timeout value of zero causes the call to wait indefinitely until a message arrives.
- Parameters:
- timeout: the timeout value (in milliseconds).
- Returns:
- The next message produced for this message consumer, or null if one is not available.
- Throws:
- JMSException if JMS fails to receive the next message because of an error.
- receiveNoWait
public Message receiveNoWait() throws JMSException
Receive the next message if one is immediately available.
- Returns:
- The next message produced for this message consumer, or null if one is not available.
- Throws:
- JMSException if JMS fails to receive the next message because of an error.
- setMessageListener
public void setMessageListener(MessageListener listener) throws JMSException
Set the message consumer's MessageListener.
- Parameters:
- messageListener: the messages are delivered to this listener.
- Throws:
- JMSException if JMS fails to set message listener because of a JMS error.
- See also:
- getMessageListener
- close
public void close() throws JMSException
Because a provider can allocate some resources outside the JVM 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 message listener in progress has completed.
- Throws:
- JMSException if JMS fails to close the consumer because of an error.
WebSphere is a trademark of the IBM Corporation in the United States, other countries, or both.
IBM is a trademark of the IBM Corporation in the United States, other countries, or both.