Amazon Simple Queue Service
Developer Guide (API Version 2012-11-05)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

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 DelaySeconds attribute.

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.

A timeline graphic that illustrates the relationship between delay queues and visibility timeouts.

Note

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.

Important

All Amazon SQS queues have delay functionality enabled. You can turn any queue that you create using the 2008-01-01 or 2009-02-01 API versions into a delay queue. Message timers are available in the 2011-10-01 API version and later API versions. If you want to apply specific delay values to individual messages, you must use the 2011-10-01 API version or later API versions.

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

  1. Sign in to the AWS Management Console and open the Amazon SQS console at https://console.aws.amazon.com/sqs/.

  2. Click Create New Queue.

    AWS Management Console Create New Queue button
  3. In the Create New Queue dialog box, enter a name for your queue (e.g., MyQueue) in the Queue Name field.

    AWS Management Console Create New Queue Dialog box
  4. Enter a positive integer value (e.g., 30) for the Delivery Delay attribute.

    You can leave the default value settings for the remaining fields or enter new values.

    AWS Management Console Create New Queue Dialog with Delivery Delay highlighted.
  5. 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.

To set a new delivery delay value for an existing queue

  1. Select the Configure Queue action with an existing queue highlighted.

    AWS Management Console Amazon SQS Queue Actions drop down list with Configure Queue highlighted.
  2. Change the value of Delivery Delay to a positive integer value.

    AWS Management Console Amazon SQS Configure Queue dialog box with Dialog Delay highlighted.
  3. Click Save Changes.

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=2011-10-01
&Expires=2011-10-20T22%3A52%3A43PST
&AUTHPARAMS

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=2011-10-01
&Expires=2011-10-20T22%3A52%3A43PST
&AUTHPARAMS