[英]Amazon SQS Messages not deleting in PHP
I list the messages in my Amazon SQS queue and then have the option to delete them, one at a time. 我在Amazon SQS队列中列出了消息,然后可以选择一次删除它们。 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 安德烈
The if()
condition in your delete code is wrong. 删除代码中的
if()
条件错误。 Your condition will always return true. 您的条件将始终返回true。
You need to make the request, then check if $response->isOK()
is true
or false
. 您需要发出请求,然后检查
$response->isOK()
是true
还是false
。 If the request was completed successfully, AWS will return a 2xx
status code, and the isOK()
method will return true
. 如果请求成功完成,AWS将返回
2xx
状态代码,而isOK()
方法将返回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. 如果进行了更改并开始看到失败,请使用
print_r($response->body)
查看SQS发回的错误消息。 That should help you debug. 那应该可以帮助您调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.