public interface ClientConsumer extends AutoCloseable
receive() methods
which will block until a message is received (or a timeout expires) or asynchronously
by setting a MessageHandler.
receive() methods are called.ClientSession.createConsumer(String)| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the consumer.
|
ConsumerContext |
getConsumerContext()
The server's ID associated with this consumer.
|
Exception |
getLastException()
Returns the last exception thrown by a call to this consumer's MessageHandler.
|
MessageHandler |
getMessageHandler()
Returns the MessageHandler associated to this consumer.
|
boolean |
isClosed()
Returns whether the consumer is closed or not.
|
ClientMessage |
receive()
Receives a message from a queue.
|
ClientMessage |
receive(long timeout)
Receives a message from a queue.
|
ClientMessage |
receiveImmediate()
Receives a message from a queue.
|
ClientConsumer |
setMessageHandler(MessageHandler handler)
Sets the MessageHandler for this consumer to consume messages asynchronously.
|
ConsumerContext getConsumerContext()
ClientMessage receive() throws org.apache.activemq.artemis.api.core.ActiveMQException
This call will block indefinitely until a message is received.
Calling this method on a closed consumer will throw an ActiveMQException.
org.apache.activemq.artemis.api.core.ActiveMQException - if an exception occurs while waiting to receive a messageClientMessage receive(long timeout) throws org.apache.activemq.artemis.api.core.ActiveMQException
This call will block until a message is received or the given timeout expires.
Calling this method on a closed consumer will throw an ActiveMQException.
timeout - time (in milliseconds) to wait to receive a messagenull if the time out expiredorg.apache.activemq.artemis.api.core.ActiveMQException - if an exception occurs while waiting to receive a messageClientMessage receiveImmediate() throws org.apache.activemq.artemis.api.core.ActiveMQException
This call will never wait indefinitely for a message, it will return null if no
messages are available for this consumer.
Note however that there is a performance cost as an additional network trip to the server may required to check the queue status.
Calling this method on a closed consumer will throw an ActiveMQException.
null if there are no messages in the queue for this consumerorg.apache.activemq.artemis.api.core.ActiveMQException - if an exception occurs while waiting to receive a messageMessageHandler getMessageHandler() throws org.apache.activemq.artemis.api.core.ActiveMQException
Calling this method on a closed consumer will throw an ActiveMQException.
nullorg.apache.activemq.artemis.api.core.ActiveMQException - if an exception occurs while getting the MessageHandlerClientConsumer setMessageHandler(MessageHandler handler) throws org.apache.activemq.artemis.api.core.ActiveMQException
Calling this method on a closed consumer will throw a ActiveMQException.
handler - a MessageHandlerorg.apache.activemq.artemis.api.core.ActiveMQException - if an exception occurs while setting the MessageHandlervoid close()
throws org.apache.activemq.artemis.api.core.ActiveMQException
Once this consumer is closed, it can not receive messages, whether synchronously or asynchronously.
close in interface AutoCloseableorg.apache.activemq.artemis.api.core.ActiveMQExceptionboolean isClosed()
true if this consumer is closed, false elseException getLastException()
nullCopyright © 2023 The Apache Software Foundation. All rights reserved.