When multiple consumers retrieve messages from the same queue, a message can be processed more than once or lost if a consumer fails midway. Simple Message Queue (formerly MNS) uses a visibility timeout mechanism to prevent both outcomes.
Each queue in Simple Message Queue (formerly MNS) has a configurable visibility timeout. When a consumer retrieves a message, the message becomes invisible to all other consumers for the duration of that timeout. This gives the consumer exclusive time to process the message.
How it works
After retrieving a message, a consumer must take one of the following actions before the visibility timeout expires:
Processing succeeds: Delete the message using its receipt handle (ReceiptHandle). This permanently removes the message from the queue and confirms successful consumption.
Processing fails or takes too long: Extend the visibility timeout by calling ChangeVisibilityTimeout before it expires. If you do not extend the timeout, the message becomes visible again and another consumer may retrieve it, resulting in duplicate processing.