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 |
|---|---|
If you don't have the receipt handle for the message, you can call
|
The following code snippets demonstrate how to delete the message from your MyQueue
queue.
To run the sample
Open DeleteMessageSample.java.
Locate the following lines.
DeleteMessageRequest request = new DeleteMessageRequest();
// @TODO: set request parameters here
// invokeDeleteMessage(service, request);Replace the lines with the following new lines of code.
DeleteMessageRequest request = new DeleteMessageRequest();
request.setQueueName("MyQueue");
request.setReceiptHandle("Receipt handle you received from ReceiveMessage call");
invokeDeleteMessage(service, request);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.
To run the sample
Open AmazonSQSSamples.cs.
Comment out the code you added in the previous section (that code consisted of the following lines).
ReceiveMessage request = new ReceiveMessageRequest(); request.QueueName = "MyQueue"; ReceiveMessageSample.InvokeReceiveMessage(service, request);
Locate the following lines.
// DeleteMessageRequest request = new DeleteMessageRequest(); // @TODO: set request parameters here // DeleteMessageSample.InvokeDeleteMessage(service, request);
Replace the lines with the following new lines of code.
DeleteMessageRequest request = new DeleteMessageRequest();
request.QueueName = "MyQueue";
request.ReceiptHandle = "Receipt handle you received from ReceiveMessage call";
DeleteMessageSample.InvokeDeleteMessage(service, request);Run the sample.
The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.
To run the sample
Open DeleteMessageSample.pl.
Locate the following line.
# invokeDeleteMessage($service, $request);
Replace the line with the following new lines of code.
my $request = Amazon::SQS::Model::DeleteMessageRequest->new({
QueueName => "MyQueue",
ReceiptHandle => "Receipt handle you received from ReceiveMessage call"
});
invokeDeleteMessage($service, $request);Run the sample.
The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.
To run the sample
Open DeleteMessageSample.php.
Locate the following line.
// invokeDeleteMessage($service, $request);
Replace the line with the following new lines of code.
require_once ('Amazon/SQS/Model/DeleteMessageRequest.php');
$request = new Amazon_SQS_Model_DeleteMessageRequest();
$request->setQueueName('MyQueue');
$request->setReceiptHandle('Receipt handle you received from ReceiveMessage call');
invokeDeleteMessage($service, $request);Run the sample.
The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.
To run the sample
Open AmazonSQSSamples.vb.
Comment out the code you added in the previous section (that code consisted of the following lines).
Dim request As New ReceiveMessageRequest() request.QueueName = "MyQueue" ReceiveMessageSample.InvokeReceiveMessage(service, request)
Locate the following lines.
' Dim request As New DeleteMessageRequest() ' @TODO: set request parameters here ' DeleteMessageSample.InvokeDeleteMessage(service, request)
Replace the lines with the following new lines of code.
Dim request As New DeleteMessageRequest()
request.QueueName = "MyQueue"
request.ReceiptHandle = "Receipt handle you received from ReceiveMessage call"
DeleteMessageSample.InvokeDeleteMessage(service, request)Run the sample.
The message is deleted from the MyQueue queue. The response includes the request ID that Amazon SQS assigned to your request.
To run the sample
In the scratchpad, select DeleteMessage from the Explore API list box.
Enter MyQueue in the Queue Name field.
Enter the receipt handle (which you received from the preceding
ReceiveMessage call) in the Receipt Handle
field.
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.