Class MQMessageConsumer
java.lang.Object
com.ibm.mq.jakarta.jms.MQRoot
com.ibm.mq.jakarta.jms.MQMessageConsumer
- All Implemented Interfaces:
JmsMessageConsumer, JmsPropertyContext, JmsReadablePropertyContext, jakarta.jms.MessageConsumer, Serializable, AutoCloseable, Map<String,Object>
- Direct Known Subclasses:
MQQueueReceiver, MQTopicSubscriber
public class MQMessageConsumer
extends MQRoot
implements jakarta.jms.MessageConsumer, JmsMessageConsumer
MQMessageConsumer is the parent interface for all message consumers. A client uses a message
consumer to receive messages from a destination.
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the message consumer.jakarta.jms.DestinationGets the message destination.jakarta.jms.MessageListenerGets the message consumer's message listener.Gets this message consumer's message selector expression.booleanIndicates whether locally published messages are inhibited.jakarta.jms.Messagereceive()Receives the next message produced for this message consumer.jakarta.jms.Messagereceive(long timeout) Receives the next message that arrives within the specified timeout interval.jakarta.jms.MessageReceives the next message if one is immediately available.voidsetMessageListener(jakarta.jms.MessageListener listener) Sets the message consumer's message listener.Methods inherited from class MQRoot
clear, containsKey, containsValue, entrySet, equals, get, getBooleanProperty, getByteProperty, getBytesProperty, getCharProperty, getDoubleProperty, getFloatProperty, getIntProperty, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, hashCode, isEmpty, keySet, propertyExists, put, putAll, remove, setBatchProperties, setBooleanProperty, setByteProperty, setBytesProperty, setCharProperty, setDoubleProperty, setFloatProperty, setIntProperty, setLongProperty, setObjectProperty, setShortProperty, setStringProperty, size, valuesMethods inherited from interface JmsPropertyContext
setBatchProperties, setBooleanProperty, setByteProperty, setBytesProperty, setCharProperty, setDoubleProperty, setFloatProperty, setIntProperty, setLongProperty, setObjectProperty, setShortProperty, setStringProperty, toJsonMethods inherited from interface JmsReadablePropertyContext
getBooleanProperty, getByteProperty, getBytesProperty, getCharProperty, getDoubleProperty, getFloatProperty, getIntProperty, getLongProperty, getObjectProperty, getPropertyNames, getShortProperty, getStringProperty, propertyExists, stringifyMeMethods inherited from interface Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
close
public void close() throws jakarta.jms.JMSExceptionCloses the message consumer. Because a provider can allocate some resources outside the Java Virtual Machine on behalf of message consumers, 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:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException- if the operation fails.
-
getDestination
public jakarta.jms.Destination getDestination() throws jakarta.jms.JMSExceptionGets the message destination.- Returns:
- the destination - either queue or topic.
- Throws:
jakarta.jms.JMSException- if the operation fails.
-
getMessageListener
public jakarta.jms.MessageListener getMessageListener() throws jakarta.jms.JMSExceptionGets the message consumer's message listener.- Specified by:
getMessageListenerin interfacejakarta.jms.MessageConsumer- Returns:
- the listener for the message consumer, or null if a listener is not set.
- Throws:
jakarta.jms.JMSException- if the operation fails.
-
getMessageSelector
Gets this message consumer's message selector expression.- Specified by:
getMessageSelectorin interfacejakarta.jms.MessageConsumer- Returns:
- this message consumer's message selector.
- Throws:
jakarta.jms.JMSException- if the operation fails.
-
receive
public jakarta.jms.Message receive() throws jakarta.jms.JMSExceptionReceives 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:
receivein interfacejakarta.jms.MessageConsumer- Returns:
- the next message produced for this message consumer, or null if this message consumer is concurrently closed
- Throws:
jakarta.jms.JMSException- if the JMS provider fails to receive the next message due to an internal error.
-
receive
public jakarta.jms.Message receive(long timeout) throws jakarta.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:
receivein interfacejakarta.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:
jakarta.jms.JMSException- if the JMS provider fails to receive the next message due to an internal error.
-
receiveNoWait
public jakarta.jms.Message receiveNoWait() throws jakarta.jms.JMSExceptionReceives the next message if one is immediately available.- Specified by:
receiveNoWaitin interfacejakarta.jms.MessageConsumer- Returns:
- the next message produced for this message consumer, or null if one is not available
- Throws:
jakarta.jms.JMSException- if the JMS provider fails to receive the next message due to an internal error.
-
setMessageListener
public void setMessageListener(jakarta.jms.MessageListener listener) throws jakarta.jms.JMSException Sets the message consumer's message listener.- Specified by:
setMessageListenerin interfacejakarta.jms.MessageConsumer- Parameters:
listener- the messages are delivered to this listener.- Throws:
jakarta.jms.JMSException- if the operation fails.- See Also:
-
getNoLocal
public boolean getNoLocal() throws jakarta.jms.JMSExceptionIndicates whether locally published messages are inhibited.- Specified by:
getNoLocalin interfaceJmsMessageConsumer- Returns:
- set to true if locally published messages are being inhibited.
- Throws:
jakarta.jms.JMSException- if the message consumer is closed
-