Adesh Gautam
Adesh Gautam

Reputation: 51

Delay in getting messages from AWS SQS

I am adding messages in SQS on Lambda and then receiving the messages inside a container on ECS. The problem is there is a 10-15 seconds of delay when I am receiving the messages on the container.

On the container a loop is running indefinitely every 1 second where I am getting messages and if available processing it.

Example: Suppose the message is added in SQS at 15:20:00 but I am able to get that message at 15:20:15 on ECS. These 15 seconds are too long for my use case.

Can this time be reduced ? Assuming that there are multiple producers and consumers is there any alternative solution ?

Upvotes: 1

Views: 1924

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269081

If your workers are continually polling the Amazon SQS queue, they can reduce the amount of requests by specifying WaitTimeSeconds=20 (which is its maximum value).

This tells Amazon SQS to wait until at least one message is available, to a maximum of 20 seconds. If no messages are available after 20 seconds, an empty set of messages is returned. However, if one or more messages appear in the queue, then the call returns immediately without waiting for 20 seconds.

This reduces the frequency of calls to SQS and might increase stability in your application.

Upvotes: 1

Related Questions