Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS SQS not honouring WaitTimeSeconds [duplicate]

I am using the AWS SDK in PHP to communicate with an SQS queue. At the moment the queue just has simple test messages contained within it. I am attempting to read the next 10 messages from the queue. To do this I have set MaximumNumberOfMessages to 10 and also set the WaitTimeSeconds to 20.

My understanding of this should be that the SqsClient will connect and consume messages from the queue until it has either the number of messages (10) or reaches the timeout (20) seconds.

However the client is returning almost instantly and with only 3-4 messages (now there are +20 messages in the queue). When there were only 4-5 messages it would return with just one message.

I have also set the VisibilityTimeout to just be 1 second, and am not running the test script in a loop, just firing manually from the CLI.

The array I am passing to SqsClient receiveMessage is :

[
        'QueueUrl' => $this->uri,
        'MaxNumberOfMessages' => 10,
        'VisibilityTimeout' => 1,
        'WaitTimeSeconds' => 20,
]

Any ideas why the call isn't waiting for the full 20 seconds at least (for small number of queue messages), and not returning more than a few messages (for a fuller queue) ?

Thanks

like image 509
Graeme Avatar asked Sep 13 '16 13:09

Graeme


People also ask

Is it possible for duplicate messages to be received within SQS?

Unlike standard queues, FIFO queues don't introduce duplicate messages. FIFO queues help you avoid sending duplicates to a queue. If you retry the SendMessage action within the 5-minute deduplication interval, Amazon SQS doesn't introduce any duplicates into the queue.

What is Waittimeseconds in SQS?

In most cases, you can set the ReceiveMessage wait time to 20 seconds. If 20 seconds is too long for your application, set a shorter ReceiveMessage wait time (1 second minimum).

Does SQS guarantee exactly-once delivery?

It does not guarantee exactly-once delivery but it does guarantee exactly-once processing. What this means is that the SQS FIFO queue has to receive acknowledgement from the consumer that a message is processed before it stops returning it on future message requests.

Why are messages not visible in SQS?

To prevent other consumers from processing the message again, Amazon SQS sets a visibility timeout, a period of time during which Amazon SQS prevents other consumers from receiving and processing the message. The default visibility timeout for a message is 30 seconds. The minimum is 0 seconds. The maximum is 12 hours.


1 Answers

My understanding (and observations while using SQS) is different that yours. Just because you have set a MaxMessages to 10, doesn't mean you will always get 10, you will get upto 10, but could be less.

The WaitTimeInSeconds is how long it will wait before it will return with no messages, but since it is finding messages in your case, it is returning immediately.

The purpose of the 'WaitTimeInSeconds' is to cut down on the number of calls you need to make in a tight loop asking 'do you have any messages for me' and constantly getting back none.

like image 89
E.J. Brennan Avatar answered Sep 27 '22 19:09

E.J. Brennan