$listMessagesResult = $queueRestProxy->listMessages("myqueue",$message_options); $messages = $listMessagesResult->getQueueMessages(); foreach($messages as $message){ /* --------------------- Process message. --------------------- */ echo "Peeked message:<br />"; echo "Message Id: ".$message->getMessageId()."<br />"; echo "Date: ".date_format($message->getInsertionDate(), 'Y-m-d')."<br />"; echo "Message text: ".$message->getMessageText()."<br /><br />"; // Get message Id and pop receipt. $messageId = $message->getMessageId(); $popReceipt = $message->getPopReceipt(); // Delete message. $queueRestProxy->deleteMessage("myqueue", $messageId, $popReceipt);
<?php require_once "WindowsAzure/WindowsAzure.php"; require_once 'PHPUnit\autoload.php'; use WindowsAzure\Common\ServicesBuilder; use WindowsAzure\Common\ServiceException; use WindowsAzure\Queue\Models\ListMessagesOptions; // Create Connection String $connectionString = "DefaultEndpointsProtocol=http;AccountName=[yourAccount];AccountKey=[yourKey]"; // Create queue REST proxy. $queueRestProxy = ServicesBuilder::getInstance()->createQueueService($connectionString); // Set list message options. $message_options = new ListMessagesOptions(); $message_options->setVisibilityTimeoutInSeconds(10); $message_options->setNumberOfMessages(1); // Get messages. try{ $listMessagesResult = $queueRestProxy->listMessages("myqueue",$message_options); $messages = $listMessagesResult->getQueueMessages(); foreach($messages as $message){ /* --------------------- Process message. --------------------- */ echo "Peeked message:<br />"; echo "Message Id: ".$message->getMessageId()."<br />"; echo "Date: ".date_format($message->getInsertionDate(), 'Y-m-d')."<br />"; echo "Message text: ".$message->getMessageText()."<br /><br />"; // Get message Id and pop receipt. $messageId = $message->getMessageId(); $popReceipt = $message->getPopReceipt(); // Delete message. $queueRestProxy->deleteMessage("myqueue", $messageId, $popReceipt); } } catch(ServiceException $e){ // Handle exception based on error codes and messages. // Error codes and messages are here: // http://msdn.microsoft.com/en-us/library/windowsazure/dd179446.aspx $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."<br />"; } ?>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท