Skip to content
Advertisement

How the function changeMessageVisibility of sqs message extends the visibility time?

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

Advertisement

Answer

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.

Advertisement