skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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:

    aws sqs send-message --queue-url https://sqs.ap-southeast-2.amazonaws.com/111/foo --message-body message1
    

    You can then retrieve a message with:

    aws sqs receive-message --queue-url https://sqs.ap-southeast-2.amazonaws.com/111/foo
    

    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:

    aws sqs delete-message --queue-url https://sqs.ap-southeast-2.amazonaws.com/111/foo --receipt-handle xxx
    

    You can also specify the visibility timeout when retrieving a message, such as 5 seconds:

    aws sqs receive-message --queue-url https://sqs.ap-southeast-2.amazonaws.com/111/foo --visibility-timeout 5
    

    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):

    aws sqs receive-message --queue-url https://sqs.ap-southeast-2.amazonaws.com/111/foo --wait-time 20
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search