public class SQSMessageConsumerPrefetch extends java.lang.Object implements java.lang.Runnable, PrefetchManager
receive turn around times.
Each message consumer creates one prefetch thread.
This runs until the message consumer is closed and in-progress SQS
receiveMessage call returns.
Uses SQS receiveMessage with long-poll wait time of 20 seconds.
Add re-tries on top of AmazonSQSClient re-tries on SQS calls.
| Modifier and Type | Class and Description |
|---|---|
static class |
SQSMessageConsumerPrefetch.MessageManager |
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
ALL |
protected ExponentialBackoffStrategy |
backoffStrategy
AWS SQS SDK with default backup strategy already re-tries 3 times
exponentially.
|
protected boolean |
closed
States of the prefetch thread
|
protected java.util.ArrayDeque<SQSMessageConsumerPrefetch.MessageManager> |
messageQueue
Internal buffer of Messages.
|
protected int |
messagesPrefetched
Counter on how many messages are prefetched into internal messageQueue.
|
protected int |
retriesAttempted
Controls the number of retry attempts to the SQS
|
protected boolean |
running |
protected static int |
WAIT_TIME_SECONDS |
| Modifier and Type | Method and Description |
|---|---|
protected javax.jms.Message |
convertToJMSMessage(Message message)
Convert the return SQS message into JMS message
|
SQSMessageConsumer |
getMessageConsumer()
This is used to determine the state of the consumer, when the message
listener scheduler is processing the messages.
|
protected java.util.List<Message> |
getMessages(int prefetchBatchSize)
Call
receiveMessage with long-poll wait time of 20 seconds
with available prefetch batch size and potential re-tries. |
protected boolean |
isClosed() |
void |
messageDispatched()
Notify the prefetchThread that the message is dispatched from
messageQueue when user calls for receive or message listener onMessage is
called.
|
protected void |
nackQueueMessages() |
protected void |
notifyStateChange() |
protected void |
processReceivedMessages(java.util.List<Message> messages)
Converts the received message to JMS message, and pushes to messages to
either callback scheduler for asynchronous message delivery or to
internal buffers for synchronous message delivery.
|
void |
run()
Runs until the message consumer is closed and in-progress SQS
receiveMessage call returns. |
protected void |
setMessageListener(MessageListener messageListener)
Sets the message listener.
|
protected void |
sleep(long sleepTimeMillis)
Sleeps for the configured time.
|
protected void |
waitForPrefetch() |
protected void |
waitForStart() |
protected static final int WAIT_TIME_SECONDS
protected static final java.lang.String ALL
protected final java.util.ArrayDeque<SQSMessageConsumerPrefetch.MessageManager> messageQueue
protected int messagesPrefetched
protected volatile boolean closed
protected volatile boolean running
protected int retriesAttempted
protected ExponentialBackoffStrategy backoffStrategy
public SQSMessageConsumer getMessageConsumer()
PrefetchManagergetMessageConsumer in interface PrefetchManagerprotected void setMessageListener(MessageListener messageListener)
If message listener is set, the existing messages on the internal buffer will be pushed to session callback scheduler.
If message lister is set to null, then the messages on the internal buffer of session callback scheduler will be negative acknowledged, which will be handled by the session callback scheduler thread itself.
public void run()
receiveMessage call returns.
This blocks if configured number of prefetched messages are already received or connection has not started yet.
After consumer is closed, all the messages inside internal buffer will be negatively acknowledged.
run in interface java.lang.Runnableprotected java.util.List<Message> getMessages(int prefetchBatchSize) throws java.lang.InterruptedException
receiveMessage with long-poll wait time of 20 seconds
with available prefetch batch size and potential re-tries.java.lang.InterruptedExceptionprotected void processReceivedMessages(java.util.List<Message> messages)
protected void waitForPrefetch()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected javax.jms.Message convertToJMSMessage(Message message) throws JMSException
message - SQS message to convertJMSExceptionprotected void nackQueueMessages()
protected void waitForStart()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void messageDispatched()
PrefetchManagermessageDispatched in interface PrefetchManagerprotected void notifyStateChange()
protected void sleep(long sleepTimeMillis)
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected boolean isClosed()