How the function changeMessageVisibility of sqs message extends the visibility time?
Asked Answered
M

3

8

In its documentation of ChangeMessageVisibility function, Amazon gives the following example:

For example, you have a message with a visibility timeout of 5 minutes. After 3 minutes, you call ChangeMessageVisibility with a timeout of 10 minutes. You can continue to call ChangeMessageVisibility to extend the visibility timeout to the maximum allowed time. If you try to extend the visibility timeout beyond the maximum, your request is rejected.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ChangeMessageVisibility.html

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-sqs-visibility-timeout.html

so, after I change the visibility time of msg to 10 minutes, it has 10 minutes (reset the timer), 12 minutes (add 10 minutes to the 2 minutes remaining) or 7 minutes left (extend the timer from the time it started - 3 minutes ago)?

Margravine answered 25/4, 2019 at 10:1 Comment(0)
G
13

The message has 10 minutes left. ChangeMessageVisibility sets the timer to a new value, from which it starts counting down.

The documentation confuses the issue with the mention of 5 and 3 minutes. The point appears to be that you need to make the call before the timer expires, otherwise it is too late, because the message has already become visible again and may have been delivered to another consumer.

Guenna answered 26/4, 2019 at 3:21 Comment(1)
hey, i know you answered this 2 years ago, but if you recall : do they mean by the maximum visibility timeout 12h with the passed time since receiving the message and extending its visibility timeout, or is it always 12h ?Empressement
A
1

It means time lapsed since message receive + visibility timeout parameter value cannot exceed 43200, see here for details https://medium.com/@Peiti_Li/understanding-aws-sqs-visibility-timeout-abeb5dec4497

Anglocatholic answered 16/9, 2021 at 6:56 Comment(1)
This blog post gives a better view, but it's not clear yet how the API operates. For e.g.: 1) I run a get message (visibility timeout is 30sec), 2) 10 seconds elapses, 3) I call changeVisibilityTimeout(10 sec), what is the output after the call? Do I have 30 seconds to process the message from the time of the request (30 default + 10 requested) or do I have 10 seconds to process the message after the request?Ainslee
P
0

Accordingly with @Michael, just adding some extra reference to AWS docs, there´s a clearer explanation at this link: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html#changing-message-visibility-timeout

For example, if the default timeout for a queue is 60 seconds, 15 seconds have elapsed since you received the message, and you send a ChangeMessageVisibility call with VisibilityTimeout set to 10 seconds, the 10 seconds begin to count from the time that you make the ChangeMessageVisibility call. Thus, any attempt to change the visibility timeout or to delete that message 10 seconds after you initially change the visibility timeout (a total of 25 seconds) might result in an error.

Purlin answered 19/1, 2023 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.