When a consumer receives a message from a queue, the message becomes temporarily invisible to other consumers. This prevents multiple consumers from processing the same message simultaneously. The duration of this invisibility is controlled by the visibility timeout period.
Visible and invisible states
A message in a Simple Message Queue (SMQ, formerly MNS) queue has two states:
Visible: The message is available in the queue. Any consumer can receive and process it. A consumer is a service or application that receives and processes messages.
Invisible: A consumer has received the message. Other consumers cannot see or receive it until the visibility timeout period expires.
Message lifecycle
A producer sends a message to the queue. The message is visible.
A consumer receives the message. The message becomes invisible and the visibility timeout period starts.
The consumer processes the message and deletes it from the queue.
If the consumer does not delete the message before the visibility timeout period expires, the message becomes visible again and can be received by the same or a different consumer.
Visibility timeout period
The visibility timeout period is the duration between when a consumer receives a message and when that message becomes visible to other consumers again.
| Parameter | Value |
|---|---|
| Valid values | 1 to 143,200 seconds (12 hours) |
| Default | 30 seconds |
Failure recovery
If a consumer fails to process and delete a message -- due to application errors, crashes, or connection failures -- the message automatically becomes visible again after the visibility timeout period expires. Another consumer can then pick it up for reprocessing.
A visibility timeout that is too high delays failure recovery. For example, with a 12-hour timeout, other consumers must wait the full 12 hours before they can reprocess the message, even if the original consumer crashed immediately after receiving it.
Set the visibility timeout period
Console
Set the Visibility Timeout Period when you create or edit a queue. For more information, see Create a queue.
API
Call the ChangeMessageVisibility operation to adjust the visibility timeout period of a message that has already been received.