public class SQSMessageConsumer extends Object implements javax.jms.MessageConsumer, javax.jms.QueueReceiver
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.
|
javax.jms.MessageListener |
getMessageListener()
Gets the message consumer's MessageListener.
|
String |
getMessageSelector()
This method is not supported.
|
javax.jms.Queue |
getQueue()
Gets the queue destination associated with this queue receiver, where the
messages are delivered from.
|
javax.jms.Message |
receive()
This call blocks indefinitely until a message is produced or until this
message consumer is closed.
|
javax.jms.Message |
receive(long timeout)
This call blocks until a message arrives, the timeout expires, or this
message consumer is closed.
|
javax.jms.Message |
receiveNoWait()
Receives the next message if one is immediately available.
|
void |
setMessageListener(javax.jms.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 javax.jms.Queue getQueue()
throws javax.jms.JMSException
getQueue in interface javax.jms.QueueReceiverjavax.jms.JMSExceptionpublic javax.jms.MessageListener getMessageListener()
throws javax.jms.JMSException
getMessageListener in interface javax.jms.MessageConsumerjavax.jms.JMSExceptionpublic void setMessageListener(javax.jms.MessageListener listener)
throws javax.jms.JMSException
setMessageListener in interface javax.jms.MessageConsumerlistener - a message listener to use for asynchronous message deliveryjavax.jms.JMSException - If the message consumer is closedpublic javax.jms.Message receive()
throws javax.jms.JMSException
receive in interface javax.jms.MessageConsumerjavax.jms.JMSException - On internal errorpublic javax.jms.Message receive(long timeout)
throws javax.jms.JMSException
receive in interface javax.jms.MessageConsumertimeout - the timeout value (in milliseconds)javax.jms.JMSException - On internal errorpublic javax.jms.Message receiveNoWait()
throws javax.jms.JMSException
receiveNoWait in interface javax.jms.MessageConsumerjavax.jms.JMSException - On internal errorpublic void close()
throws javax.jms.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.
close in interface javax.jms.MessageConsumerjavax.jms.JMSException - On internal error.public String getMessageSelector() throws javax.jms.JMSException
getMessageSelector in interface javax.jms.MessageConsumerjavax.jms.JMSExceptionprotected void stopPrefetch()
protected void startPrefetch()
Copyright © 2022. All rights reserved.