When you receive a message from the SQS queue, the message (by default) returns to the queue after 30 seconds. This applies to cases where the processing of a message fails and the message needs to be processed again.
Once the message has been successfully processed, use deleteMessage to delete the message. You will need the value of receiptHandle from the message when you received it from receiveMessage to delete the message.
If typical processing of your message may take more than 30 seconds, you can set up a queue to increase the time to "return to the queue". This is called the "Default Visibility Timeout" in the SQS queue configuration.
Also keep in mind that Amazon SQS works in such a way that:
- messages can be received out of order compared to how they were added to the queue
- Messages can be received twice, so allow the message handler to handle these cases.
source share