Reputation: 2386
I list the messages in my Amazon SQS queue and then have the option to delete them, one at a time. When I delete the message I get a SUCCESS message back. However, not a single message is deleted and they all return to the queue.
Here is the list queue code:
<?php
include_once("sdk.class.php");
// Instantiate
$sqs = new AmazonSQS();
$rows = $sqs->get_queue_size('https://sqs.us-east-1.amazonaws.com/199992002821/SomeQueueSQS');
echo "<table>";
echo "<tr>";
echo "<td width=20 valign=top bgcolor=" . $adHeading . " align=left><strong>No</strong></td>";
echo "<td width=200 valign=top bgcolor=" . $adHeading . " align=left><strong>Message</strong></td>";
echo "<td width=50 align='right' bgcolor=" . $adHeading . "><a href='sqs.php'><img src='images/icon_refresh.png' border='0'></a></td>";
echo "</tr>";
for ($j = 0; $j < $rows; ++$j)
{
// Get Message
$response = $sqs->receive_message('https://sqs.us-east-1.amazonaws.com/199992002821/SomeQueueSQS', array(
'VisibilityTimeout' => 30
));
$body = $response->body->ReceiveMessageResult->Message[0]->Body;
$rcpt_hand=($response->body->ReceiveMessageResult->Message[0]->ReceiptHandle);
$id = $j + 1;
echo "<tr>";
echo "<td valign=top bgcolor=" . $bgcolor . ">$id</td>";
echo "<td valign=top bgcolor=" . $bgcolor . ">$body</td>";
echo "<td valign=top><a href=sqsdelete.php?sid=$rcpt_hand><img src=images/icon_delete.gif border=0 width=18 height=18></a></td>";
echo "</tr>";
}
echo "</table>";
?>
Here is the delete code:
<?php
if ($response = $sqs->delete_message('https://sqs.us-east-1.amazonaws.com/199992002821/SomeQueueSQS', $rcpt_hand)) {
echo "Message deleted<br>";
} else {
echo "Message not deleted<br>";
}
// Get list of unprocessed and valid messages
$rows = $sqs->get_queue_size('https://sqs.us-east-1.amazonaws.com/199992002821/SomeQueueSQS');
echo "<table>";
etc...
Thanks
Andre
Upvotes: 0
Views: 1838
Reputation: 6945
The if()
condition in your delete code is wrong. Your condition will always return true.
You need to make the request, then check if $response->isOK()
is true
or false
. If the request was completed successfully, AWS will return a 2xx
status code, and the isOK()
method will return true
.
If you make that change and start seeing failures, use print_r($response->body)
to view the error message that SQS is sending back. That should help you debug.
Upvotes: 1