Amazon Simple Queue Service
Getting Started Guide (API Version 2011-10-01)
Print this pageEmail this pageGo to the ForumsView the PDFShare this page on TwitterShare this page on FacebookBookmark this page on DeliciousSubmit this page to RedditSubmit this page to DiggDid this page help you?  Yes  No   Tell us about it...

Deleting a Message

Once you receive the message, you must delete it from the queue to acknowledge that you processed the message and no longer need it. You specify which message to delete by providing the receipt handle that Amazon SQS returned when you received the message. You can delete only one message per call. You can delete an entire queue with a call to DeleteQueue, even if the queue has messages in it.

[Note]Note

If you don't have the receipt handle for the message, you can call ReceiveMessage again and receive the message again. Each time you receive the message, you get a different receipt handle. Use the latest receipt handle when calling DeleteMessage, otherwise your message might not be deleted from the queue.

The following examples demonstrate how to delete the message from your MyQueue queue.

AWS Management Console

To delete a message

  1. In the AWS Management Console select a queue.

    AWS Management Console queue list: select queue
  2. Select View/Delete Messages from the Queue Actions drop-down list.

    [Note]Note

    The Queue Actions drop-down list is available only if a queue is selected.

    AWS Management Console View or Delete SQS message
  3. Click Start Polling for Messages to view a message from the queue.

    AWS Management Console start polling for SQS messages dialog box
    [Note]Note

    The Start Polling for Messages dialog box will not appear if you have previously selected the Don't show this again checkbox.

    The View/Delete Messages dialog box displays a message from the queue.

    AWS Management Console View/Delete dialog box receiving message
  4. Select the message you want to delete.

    AWS Management Console message to be deleted
  5. Click Delete 1 Message to delete the selected message.

    A Delete Messages confirmation dialog box appears.

    AWS Management Console message to be deleted
  6. Click Yes, Delete Checked Messages.

    The selected message is deleted.

  7. Click Close to close the View/Delete Messages dialog box.

Scratchpad

To run the sample

  1. In the scratchpad, select DeleteMessage from the Explore API list box.

  2. Enter the queue URL in the Queue URL field.

  3. Enter the receipt handle (which you received from the preceding ReceiveMessage call) in the Receipt Handle field.

  4. Select one of the following:

    • To invoke the request, click Invoke Request. Amazon SQS returns a response.

    • To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser. Amazon SQS returns a response.

    • To view the string to sign, click Display String to Sign.

Java

To run the sample

  1. Open SimpleQueueServiceSample.java.

    The following section of the code deletes a message:

    // Delete a message
    System.out.println("Deleting a message.\n");
    String messageRecieptHandle = messages.get(0).getReceiptHandle();
    sqs.deleteMessage(new DeleteMessageRequest()
        .withQueueUrl(myQueueUrl)
        .withReceiptHandle(messageRecieptHandle));
    
  2. Compile and run the sample.

    The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.

C#

To run the sample

  1. Open Program.cs.

    The following section of the code deletes a message:

    //Deleting a message
    Console.WriteLine("Deleting the message.\n");
    DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
    deleteRequest.QueueUrl = myQueueUrl;
    deleteRequest.ReceiptHandle = messageRecieptHandle;
    sqs.DeleteMessage(deleteRequest);
  2. Run the sample.

    The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.

Perl

To run the sample

  1. Open DeleteMessageSample.pl.

  2. Locate the following line.

    # invokeDeleteMessage($service, $request);
  3. Replace the line with the following new lines of code.

    my $request = Amazon::SQS::Model::DeleteMessageRequest->new({
    QueueUrl => "queue URL you received from CreateQueue call",
    ReceiptHandle => "Receipt handle you received from ReceiveMessage call"
    });
    invokeDeleteMessage($service, $request);
  4. Run the sample.

    The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.

PHP5

To run the sample

  1. Open DeleteMessageSample.php.

  2. Locate the following line.

    // invokeDeleteMessage($service, $request);
  3. Replace the line with the following new lines of code.

    require_once ('Amazon/SQS/Model/DeleteMessageRequest.php');
    $request = new Amazon_SQS_Model_DeleteMessageRequest();
    $request->setQueueUrl('queue URL you received from CreateQueue call');
    $request->setReceiptHandle('Receipt handle you received from ReceiveMessage call');
    invokeDeleteMessage($service, $request);
  4. Run the sample.

    The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.