Amazon SQS Long Polling does not return all messages

I have a requirement to read all the messages in my Amazon SQS queue in 1 read, and then sort them based on the created timestamp and do business logic on it.

To ensure that all SQS hosts are marked for messages, I have included a lengthy poll. The way I did this was to set the default timeout for the queue as 10 seconds. (Any value greater than 0 will include a lengthy poll).

However, when I tried to read the queue, he still did not give me all the messages, and I had to do several readings to get all the messages. I even included a long poll through the code for each request for receipt, it still did not work. Below is the code I'm using.

AmazonSQSClient sqsClient = new AmazonSQSClient(new ClasspathPropertiesFileCredentialsProvider());
sqsClient.setEndpoint("sqs.us-west-1.amazonaws.com");
String queueUrl = "https://sqs.us-west-1.amazonaws.com/12345/queueName";
ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(10).withWaitTimeSeconds(20);
List<Message> messages = sqsClient.receiveMessage(receiveRequest).getMessages();

I have 3 messages in the queue and every time I run the code I get a different result, sometimes I get all 3 messages, sometimes just 1. I set the visibility timeout to 2 seconds, just to exclude the messages from becoming invisible as a reason not see them in reading. This is the expected behavior for a short survey. A long survey should eliminate several polls. Am I doing something wrong here?

thanks

+4
source share
3 answers

A lengthy survey should eliminate several polls

, , . SQS , , , , - . SQS , - :

" SQS , . , , ReceiveMessage ( ) , ReceiveMessage. "

http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html ( )

, "-", SQS , ( ) , , , SQS . , " , - " " , , "... , , , " , , ".

, , .

+17

SQS , - , .

, , , , .

+1

Michael - sqlbot, SQS ( ) Long Polling. , - .. , .

, , , . , 1000 , , 10 (, , , ) . . 100 10, 10 . , , , .

- , .

http://pragmaticnotes.com/2017/11/20/amazon-sqs-long-polling-versus-short-polling/

-2
source

All Articles