I am trying the visibility timeout feature of AWS SQS using the Send and Receive Messages page provided by AWS. I have created multiple consumers by opening duplicate pages of Send and Receive Messages pages. I observed that even if I configure the visibility timeout as 1 hour, it is still received in another consumer as soon as the previous consumer poll duration times out. What’s wrong with it?
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
First of all, stop using the Send and Receive Messages page as an actual consumer.
AWS has provided that page to just manually send and receive messages from an SQS queue. While it can be used for testing purposes or for occasional message retrieval, it is not intended to be used as a an actual consumer.
If you want to play with the SQS features, use an actual consumer through AWS SDK or AWS CLI or through libraries.
However, it's worth noting that the Send and Receive Messages page can be useful for debugging and troubleshooting purposes, as it allows you to view the contents of messages in the queue, modify message attributes, and manually trigger message retrieval.
That page effectively ‘consumes’ messages, causing them to change to ‘In Flight’ and then they reappear again after the invisibility timeout. This doesn’t make it easy to play with features.
If you actually want to play with Amazon SQS and invisibility timeout, use the AWS CLI to send and receive messages. For example, if you have create a queue called
foo
, use:You can then retrieve a message with:
If you run it again immediately, it will not return a message because there are no visible messages. However, if you wait 30 seconds (or whatever you set the timeout to be) and then run it, the message should appear again.
You can then delete the message using the Receipt Handle:
You can also specify the visibility timeout when retrieving a message, such as 5 seconds:
You can also specify a Wait Time. If a message is available within the specified period,
receive-message
will return immediately. Otherwise, it will wait for the specified period before returning an empty result. Try running this command, then send a message to the queue via a different shell session (in a different window):