Amazon SQS Delay Queues
Delay queues allow you to postpone the delivery of new messages in a queue for a specific number of seconds. If you create a delay queue, any message that you send to that queue will be invisible to consumers for the duration of the delay period. You can use
CreateQueue to create a delay queue by setting the
DelaySeconds attribute to any value between 0 and 900 (15 minutes). You can also turn an existing queue into a delay queue by using
SetQueueAttributes to set the queue's
Delay queues are similar to visibility timeouts in that both features make messages unavailable to consumers for a specific period of time. The difference between delay queues and visibility timeouts is that for delay queues, a message is hidden when it is first added to the queue, whereas for visibility timeouts, a message is hidden only after a message is retrieved from the queue. The following figure illustrates the relationship between delay queues and visibility timeouts.
There is a 120,000 limit for the number of inflight messages per queue. Messages are inflight after they have been received from the queue by a consuming component, but have not yet been deleted from the queue. If you reach the 120,000 limit, you will receive an OverLimit error message from Amazon SQS. To help avoid reaching the limit, you should delete the messages from the queue after they have been processed. You can also increase the number of queues you use to process the messages.
To set delay seconds on individual messages, rather than for an entire queue, use message timers. If you send a message with a message timer, Amazon SQS uses the message timer's delay seconds value instead of the delay queue's delay seconds value. For more information, see Amazon SQS Message Timers.
Creating Delay Queues with the AWS Management Console
You can create a delay queue using the AWS Management Console by setting a Delivery Delay value that is greater than 0.
To create a delay queue with the AWS Management Console
Sign in to the AWS Management Console and open the Amazon SQS console at https://console.aws.amazon.com/sqs/.
Click Create New Queue.
In the Create New Queue dialog box, enter a name for your queue (for example,
MyQueue) in the Queue Name field.
Enter a positive integer value (for example, 30) for the Delivery Delay attribute.
You can leave the default value settings for the remaining fields or enter new values.
Click Create Queue.
You can use the AWS Management Console to change the Delivery Delay setting for an existing queue by selecting the Configure Queue action with an existing queue highlighted.
Creating Delay Queues with the Query API
The following Query API example calls the
CreateQueue action to create a delay queue that hides each message from consumers for the first 45 seconds that the message is in the queue.
How you structure the AUTHPARAMS depends on how you are signing your API request. For information on AUTHPARAMS in Signature Version 4, go to Examples of Signed Signature Version 4 Requests.
http://sqs.us-east-1.amazonaws.com/ ?Action=CreateQueue &QueueName=testQueue &Attribute.1.Name=DelaySeconds &Attribute.1.Value=45 &Version=2012-11-05 &Expires=2015-12-20T22%3A52%3A43PST &AUTHPARAMS
Queue names and queue URLs are case-sensitive.
You can also change an existing queue into a delay queue by changing the DelaySeconds attribute from its default value of 0 to a positive integer value that is less than or equal to 900. The following example calls
SetQueueAttributes to set the
DelaySeconds attribute of a queue named
testQueue to 45 seconds.
http://sqs.us-east-1.amazonaws.com/123456789012/testQueue/ ?Action=SetQueueAttributes &Attribute.Name=DelaySeconds &Attribute.Value=45 &Version=2012-11-05 &Expires=2015-12-20T22%3A52%3A43PST &AUTHPARAMS