简体   繁体   中英

Amazon AWS SQS queue message retention period

This is a 3 part question :

  1. I understand that the message retention period for an SQS queue can be set to a maximum of 14 days. I could not find a definite answer to whether you can also decrease the period back to a lesser value.

  2. Consider the queue (original retention period of 4 days) has following messages at the very moment I set the message retention period to 14 days :

    a. 10 messages in queue
    b.2 messages in flight

    How will this newly set retention period apply to these messages ? Do the 10 messages already in the queue still get deleted after 4 days or they will also be retained for 14 days ?
    If the 2 messages in flight are returned to the queue (made visible again) will they be retained for 14 days from the time they were first received in the queue ?

  3. If the current retention period of the queue is 14 days, there is a message in the queue that has been there for 5 days. Now if I decrease the retention period to 4 days, what happens to this message ?

As per the AWS Docs here the retention period of a message can be set to between 1 minute and 14 days.

Before I address the main question, in-flight messages are messages that have already been received by a queue consumer, but have not yet been and are already being processed. Changes to the queue itself should have no effect on already in-flight messages as technically they are no longer visible.

Regarding updating queue configurations. When you update the retention policy of a SQS Queue, messages already in the queue retain the retention policy of the queue that existed at the time those messages were added, and new messages will receive the retention policy that is effective from that point forward.

In your point 2 above, if you have 10 messages in the queue with a retention period of 4 days, and you update the queue to 14 days, existing messages will retain the 4 day retention policy, while new messages will have the 14 day retention policy applied. For point 3 above, the same principal applies when adjusting the queue the other way. If you have some messages that have a 14 day retention policy and you change the queue policy to be 4 days then the messages added to the queue when the retention policy was 14 days will retain the 14 day retention policy, and new messages will receive the 4 day retention policy.

To answer the above questions:

  1. The period can be decreased back to a lesser value or can be increased further up to 14 days.

  2. Yes, the 10 visible messages and the 2 messages in flight will acquire the new retention period. All the existing as well as new messages will have the new retention period, whether smaller or larger.

Kindly note that the new retention period may take up to 15 minutes before being applicable to the queue.[ https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SetQueueAttributes.html ]

  1. The message will be deleted in this case as soon as the new period gets eventually applied to the queue from the backend.

@hephalump's answer is based on tests for shorter than 15 minutes duration, therefore, they are probably giving inconsistent results. However, as per the above public doc, it can take up to 15 minutes for the changes to be actually applicable to the queue.

I have tested (3-4 times) it for retention period of more than 15 minutes and have confirmed my answer before posting.

Best Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM