awslabs / amazon-sqs-java-messaging-lib

This Amazon SQS Java Messaging Library holds the Java Message Service compatible classes, that are used for communicating with Amazon Simple Queue Service.
http://aws.amazon.com/sqs
Apache License 2.0
167 stars 146 forks source link

Prefetch prevents EC2 from autoscaling for long running transactions #27

Closed s0umyadeep closed 1 year ago

s0umyadeep commented 8 years ago

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.

kuba-aws commented 7 years ago

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

lbruun commented 5 years ago

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?