Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm getting same multiple Sqs message before visibility timeout

I set visibility time out 12 hours and max message 3, delay time 15 min, I'm get sqs message few minute after automatically I get same message again.

Why do I get multiple sqs message without timeout? After visibility time out it delete message in queue or send again sqs message?

like image 839
user8316197 Avatar asked Jan 30 '23 23:01

user8316197


1 Answers

When ReceiveMessage() is called on an Amazon SQS queue, up to 10 messages (configurable) will be retrieved from the queue.

These messages will be marked as Invisible or In-Flight. This means that the messages are still in the queue, but will not be returned via another ReceiveMessage() call. The messages will remain invisible for a period of time. The default period is configured on the queue ("Default Visibility Timeout") or when the messages are retrieved (VisibilityTimeout).

When an application has finished handling a message, it should call DeleteMessage(), passing the MessageHandle that was provided with the message. The message will then be deleted from the queue.

If the invisibility period expires before a message is deleted, it will be placed on the queue again and applications can retrieve it again. Therefore, be sure to set your invisibility timeout to be longer than an application normally takes to process a message.

It is possible that a message may be retrieved more than once from Amazon SQS. It is rare, but can happen where there are multiple processes retrieving messages simultaneously. Thus, SQS is "At least once delivery". If this is a problem, you can use FIFO Queues (not yet available in every region) that will guarantee that each message is delivered only once, but there are throughput restrictions on FIFO queues.

So, if you are receiving a message more than once:

  • You should check your invisibility timeout setting (both the default setting and the value that can be passed when you call ReceiveMessage())
  • Consider using FIFO queues
  • Have your application check whether a message has already been processed before processing it again (eg via a unique ID)
like image 155
John Rotenstein Avatar answered Feb 03 '23 22:02

John Rotenstein