public class SQSMessageConsumer
extends java.lang.Object
This message consumer does not support message selectors
A client may either synchronously receive a message consumer's messages or have the consumer asynchronously deliver them as they arrive via registering a MessageListener object.
The message consumer creates a background thread to prefetch the messages to
improve the receive turn-around times.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
closed |
static int |
PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the message consumer.
|
MessageListener |
getMessageListener()
Gets the message consumer's MessageListener.
|
java.lang.String |
getMessageSelector()
This method is not supported.
|
Queue |
getQueue()
Gets the queue destination associated with this queue receiver, where the
messages are delivered from.
|
Message |
receive()
This call blocks indefinitely until a message is produced or until this
message consumer is closed.
|
Message |
receive(long timeout)
This call blocks until a message arrives, the timeout expires, or this
message consumer is closed.
|
Message |
receiveNoWait()
Receives the next message if one is immediately available.
|
void |
setMessageListener(MessageListener listener)
Sets the message consumer's MessageListener.
|
protected void |
startPrefetch()
This starts the prefetching
|
protected void |
stopPrefetch()
This stops the prefetching
|
public static final int PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME
protected volatile boolean closed
public Queue getQueue()
throws JMSException
JMSExceptionpublic MessageListener getMessageListener()
throws JMSException
JMSExceptionpublic void setMessageListener(MessageListener listener)
throws JMSException
listener - a message listener to use for asynchronous message deliveryJMSException - If the message consumer is closedpublic Message receive()
throws JMSException
JMSException - On internal errorpublic Message receive(long timeout)
throws JMSException
timeout - the timeout value (in milliseconds)JMSException - On internal errorpublic Message receiveNoWait()
throws JMSException
JMSException - On internal errorpublic void close()
throws JMSException
This will not return until receives and/or message listeners in progress have completed. A blocked message consumer receive call returns null when this consumer is closed.
Since consumer prefetch threads use SQS long-poll feature with 20 seconds timeout, closing each consumer prefetch thread can take up to 20 seconds, which in-turn will impact the time on consumer close.
This method may be called from a message listener's onMessage method on its own consumer. After this method returns the onMessage method will be allowed to complete normally, and the callback scheduler thread will be closing the message consumer.
JMSException - On internal error.public java.lang.String getMessageSelector()
throws JMSException
JMSExceptionprotected void stopPrefetch()
protected void startPrefetch()