Amazon Simple Queue Service
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Tutorial: Sending a Message with a Timer to an Amazon SQS Queue

Message timers let you specify an initial invisibility period for a message added to a queue. For example, if you send a message with a 45-second timer, the message isn't visible to consumers for its first 45 seconds in the queue. The default (minimum) delay for a message is 0 seconds. The maximum is 15 minutes. In this tutorial you learn how to send a message with a timer to an existing queue. For more information, see Amazon SQS Message Timers.


FIFO queues don't support timers on individual messages.

For a more detailed explanation of sending messages to standard and FIFO queues, see Sending a Message to an Amazon SQS Queue.

AWS Management Console

  1. Sign in to the Amazon SQS console.

  2. From the queue list, select a queue.

  3. From Queue Actions, select Send a Message.

    The Send a Message to QueueName dialog box is displayed.

  4. To send a message to a standard queue, type the Message Body, choose Delay delivery of this message by and type a value, for example 60 seconds.

  5. Choose Send Message.

    Your message is sent and the Send a Message to QueueName dialog box is displayed, showing the attributes of the sent message.

  6. Choose Close.

AWS SDK for Java

Before you begin working with the example code, specify your AWS credentials. For more information, see Set up AWS Credentials and Region for Development in the AWS SDK for Java Developer Guide.

To send a message with a timer to a queue

  1. Copy the standard queue example program.

  2. Change the main method signature to the following:

    public static void main(String[] args) throws InterruptedException
  3. Replace the section of the code that sends the message with the following:

    // Send a message with a 5-second timer. System.out.println("Sending a message with a 5-second timer to MyQueue.\n"); SendMessageRequest request = new SendMessageRequest(myQueueUrl, "This is my message text."); request.setDelaySeconds(5); sqs.sendMessage(request); // Wait for 10 seconds. System.out.println("Waiting for 10 seconds."); Thread.sleep(10000L);
  4. Compile and run the example.

    The message is sent to the queue. The response includes the following items:

    • The message ID Amazon SQS assigns to the message.

    • An MD5 digest of the message body, used to confirm that Amazon SQS received the message correctly (for more information, see RFC1321).

    • The request ID that Amazon SQS assigned to your request.