Class SQSMessageConsumer
- All Implemented Interfaces:
jakarta.jms.MessageConsumer,jakarta.jms.QueueReceiver,AutoCloseable
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanstatic final int -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the message consumer.jakarta.jms.MessageListenerGets the message consumer's MessageListener.This method is not supported.jakarta.jms.QueuegetQueue()Gets the queue destination associated with this queue receiver, where the messages are delivered from.jakarta.jms.Messagereceive()This call blocks indefinitely until a message is produced or until this message consumer is closed.jakarta.jms.Messagereceive(long timeout) This call blocks until a message arrives, the timeout expires, or this message consumer is closed.jakarta.jms.MessageReceives the next message if one is immediately available.voidsetMessageListener(jakarta.jms.MessageListener listener) Sets the message consumer's MessageListener.protected voidThis starts the prefetchingprotected voidThis stops the prefetching
-
Field Details
-
PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME
public static final int PREFETCH_EXECUTOR_GRACEFUL_SHUTDOWN_TIME- See Also:
-
closed
protected volatile boolean closed
-
-
Method Details
-
getQueue
public jakarta.jms.Queue getQueue() throws jakarta.jms.JMSExceptionGets the queue destination associated with this queue receiver, where the messages are delivered from.- Specified by:
getQueuein interfacejakarta.jms.QueueReceiver- Returns:
- a queue destination
- Throws:
jakarta.jms.JMSException
-
getMessageListener
public jakarta.jms.MessageListener getMessageListener() throws jakarta.jms.JMSExceptionGets the message consumer's MessageListener.- Specified by:
getMessageListenerin interfacejakarta.jms.MessageConsumer- Returns:
- a message listener
- Throws:
jakarta.jms.JMSException
-
setMessageListener
public void setMessageListener(jakarta.jms.MessageListener listener) throws jakarta.jms.JMSException Sets the message consumer's MessageListener.- Specified by:
setMessageListenerin interfacejakarta.jms.MessageConsumer- Parameters:
listener- a message listener to use for asynchronous message delivery- Throws:
jakarta.jms.JMSException- If the message consumer is closed
-
receive
public jakarta.jms.Message receive() throws jakarta.jms.JMSExceptionThis call blocks indefinitely until a message is produced or until this message consumer is closed. When ConnectionState is stopped receive is paused.- Specified by:
receivein interfacejakarta.jms.MessageConsumer- Returns:
- the next message produced for this message consumer, or null if this message consumer is closed during the receive call
- Throws:
jakarta.jms.JMSException- On internal error
-
receive
public jakarta.jms.Message receive(long timeout) throws jakarta.jms.JMSException 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 (in milliseconds)- Returns:
- the next message produced for this message consumer, or null if the timeout expires or this message consumer is closed during the receive call
- Throws:
jakarta.jms.JMSException- On 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 no message is available
- Throws:
jakarta.jms.JMSException- On internal error
-
close
public void close() throws jakarta.jms.JMSExceptionCloses the message consumer.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.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException- On internal error.
-
getMessageSelector
This method is not supported.- Specified by:
getMessageSelectorin interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
stopPrefetch
protected void stopPrefetch()This stops the prefetching -
startPrefetch
protected void startPrefetch()This starts the prefetching
-