我列出了我的Amazon SQS队列中的消息,然后可以选择一次删除一个消息。当我删除消息时,我收到一条SUCCESS消息。但是,不会删除任何一条消息,它们都会返回队列。
这是列表队列代码:
<?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>";
?>
这是删除代码:
<?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...
由于
安德烈
答案 0 :(得分:1)
删除代码中的if()
条件错误。您的情况将始终返回true。
您需要提出请求,然后检查$response->isOK()
是true
还是false
。如果请求成功完成,AWS将返回2xx
状态代码,isOK()
方法将返回true
。
如果您进行了更改并开始看到失败,请使用print_r($response->body)
查看SQS正在发回的错误消息。这应该可以帮助你调试。