The Azure Queue API currently has no way to check invisible messages.
There are several situations in which a message will become invisible:
- The message was added with an
VisibilityTimeout
in the Put Message request. The message will be invisible until this initial timeout expires.
- The message has been retrieved (dequeued). Whenever a message is retrieved it will be invisible for the duration of the
VisibilityTimeout
specified by the Get Messages request, or 30 seconds by default.
- The message has expired. Messages expire after 7 days by default, or after the
MessageTTL
specified in the Put Message request. Note: after a while these messages are automatically deleted, but until that point they are there as invisible message.
Use cases
Initial VisibilityTimeout
Messages are created with an initial VisibilityTimeout
so that the message can be created now, but processed later (after the timeout expires), for whatever reason the creator has for wanting to delay this processing.
VisibilityTimeout on retrieving
The intended process for processing queue messages is:
- The application dequeues one or more messages, optionally specifying the next
VisibilityTimeout
. This timeout should be bigger than the time it takes to process the message(s).
- The application processes the message(s).
- The application deletes the messages. When the processing fails the message(s) are not deleted.
- Message(s) for which the process failed will become visible again as soon as their
VisibilityTimeout
expires, so that they can be re-tried. To prevent endless retries step 2. should start by checking the DequeueCount of the message: if it is bigger than the desired retry-count it should be deleted, instead of processed. It is good practice to copy such messages to a deadletter / poison queue (for example a queue with the original queue name plus a -poison
suffix).
MessageTTL
By default messages have a time-to-live of 7 days. If the application processing cannot handle the amount of messages being added, a backlog could build up. Adjusting the TTL will determine what happens to such backlog.
Alternatively the application could crash, so that the backlog would build up until the application would be started again.
InvisibilityTimeout
expires. – Max