amazon-sqs-java-messaging-lib icon indicating copy to clipboard operation
amazon-sqs-java-messaging-lib copied to clipboard

Prefetch prevents EC2 from autoscaling for long running transactions

Open s0umyadeep opened this issue 9 years ago • 2 comments

The SQS JMS implementation always prefetches at least one message before it invokes message listener. This prevents EC2 from autoscaling based on the number of messages in the SQS queue especially when execution of the message takes as long as 2 hours. Is there anyway we can optionally prefetch or do not prefetch at all? Unless I am missing something, there is no way I could extend the behavior of SQSMessageConsumerPrefetch class to make it usable for us. It will be nice if the prefetch is made optional.

s0umyadeep avatar Aug 23 '16 05:08 s0umyadeep

Unfortunately the current implementation does not allow you to disable prefetching entirely. Marking as a requested feature.

kuba-aws avatar Apr 25 '17 17:04 kuba-aws

Perhaps I'm misreading the code, but hasn't this indeed been fixed?

In the current version 1.0.6 I would think it can be solved like this:

SQSConnectionFactory connectionFactory = new SQSConnectionFactory(
    new ProviderConfiguration().withNumberOfMessagesToPrefetch(0), // Turn off prefetching
    AmazonSQSClientBuilder.standard()
                        .withRegion(awsRegion)
                        .withCredentials(new DefaultAWSCredentialsProviderChain()));

Or am I wrong?

lbruun avatar Jul 07 '19 12:07 lbruun