Zend_Service_WindowsAzure_Queue.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.windowsazure.storage.queue">
  4. <title>Zend_Service_WindowsAzure_Storage_Queue</title>
  5. <para>
  6. The Queue service stores messages that may be read by any client who has access to the
  7. storage account.
  8. </para>
  9. <para>
  10. A queue can contain an unlimited number of messages, each of which can be up to 8 KB in
  11. size. Messages are generally added to the end of the queue and retrieved from the front of
  12. the queue, although first in/first out (<acronym>FIFO</acronym>) behavior is not guaranteed.
  13. If you need to store messages larger than 8 KB, you can store message data as a queue or in
  14. a table and then store a reference to the data as a message in a queue.
  15. </para>
  16. <para>
  17. Queue Storage is offered by Windows Azure as a <acronym>REST</acronym> API which is wrapped
  18. by the <classname>Zend_Service_WindowsAzure_Storage_Queue</classname> class in order to
  19. provide a native PHP interface to the storage account.
  20. </para>
  21. <sect2 id="zend.service.windowsazure.storage.queue.api">
  22. <title>API Examples</title>
  23. <para>
  24. This topic lists some examples of using the
  25. <classname>Zend_Service_WindowsAzure_Storage_Queue</classname> class. Other features
  26. are available in the download package, as well as a detailed API documentation of those
  27. features.
  28. </para>
  29. <sect3 id="zend.service.windowsazure.storage.queue.api.create-queue">
  30. <title>Creating a queue</title>
  31. <para>
  32. Using the following code, a queue can be created on development storage.
  33. </para>
  34. <example id="zend.service.windowsazure.storage.queue.api.create-queue.example">
  35. <title>Creating a queue</title>
  36. <programlisting language="php"><![CDATA[
  37. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  38. $result = $storageClient->createQueue('testqueue');
  39. echo 'Queue name is: ' . $result->Name;
  40. ]]></programlisting>
  41. </example>
  42. </sect3>
  43. <sect3 id="zend.service.windowsazure.storage.queue.api.delete-queue">
  44. <title>Deleting a queue</title>
  45. <para>
  46. Using the following code, a queue can be removed from development storage.
  47. </para>
  48. <example id="zend.service.windowsazure.storage.queue.api.delete-queue.example">
  49. <title>Deleting a queue</title>
  50. <programlisting language="php"><![CDATA[
  51. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  52. $storageClient->deleteQueue('testqueue');
  53. ]]></programlisting>
  54. </example>
  55. </sect3>
  56. <sect3 id="zend.service.windowsazure.storage.queue.api.storing-queue">
  57. <title>Adding a message to a queue</title>
  58. <para>
  59. Using the following code, a message can be added to a queue on development storage.
  60. Note that the queue has already been created before.
  61. </para>
  62. <example id="zend.service.windowsazure.storage.queue.api.storing-queue.example">
  63. <title>Adding a message to a queue</title>
  64. <programlisting language="php"><![CDATA[
  65. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  66. // 3600 = time-to-live of the message, if omitted defaults to 7 days
  67. $storageClient->putMessage('testqueue', 'This is a test message', 3600);
  68. ]]></programlisting>
  69. </example>
  70. </sect3>
  71. <sect3 id="zend.service.windowsazure.storage.queue.api.read-queue">
  72. <title>Reading a message from a queue</title>
  73. <para>
  74. Using the following code, a message can be read from a queue on development storage.
  75. Note that the queue and message have already been created before.
  76. </para>
  77. <example id="zend.service.windowsazure.storage.queue.api.read-queue.example">
  78. <title>Reading a message from a queue</title>
  79. <programlisting language="php"><![CDATA[
  80. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  81. // retrieve 10 messages at once
  82. $messages = $storageClient->getMessages('testqueue', 10);
  83. foreach ($messages as $message) {
  84. echo $message->MessageText . "\r\n";
  85. }
  86. ]]></programlisting>
  87. </example>
  88. <para>
  89. The messages that are read using <methodname>getMessages()</methodname> will be
  90. invisible in the queue for 30 seconds, after which the messages will re-appear in
  91. the queue. To mark a message as processed and remove it from the queue, use the
  92. <methodname>deleteMessage()</methodname> method.
  93. </para>
  94. <example id="zend.service.windowsazure.storage.queue.api.read-queue.processexample">
  95. <title>Marking a message as processed</title>
  96. <programlisting language="php"><![CDATA[
  97. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  98. // retrieve 10 messages at once
  99. $messages = $storageClient->getMessages('testqueue', 10);
  100. foreach ($messages as $message) {
  101. echo $message . "\r\n";
  102. // Mark the message as processed
  103. $storageClient->deleteMessage('testqueue', $message);
  104. }
  105. ]]></programlisting>
  106. </example>
  107. </sect3>
  108. <sect3 id="zend.service.windowsazure.storage.queue.api.peek-queue">
  109. <title>Check if there are messages in a queue</title>
  110. <para>
  111. Using the following code, a queue can be checked for new messages. Note that the
  112. queue and message have already been created before.
  113. </para>
  114. <example id="zend.service.windowsazure.storage.queue.api.peek-queue.example">
  115. <title>Check if there are messages in a queue</title>
  116. <programlisting language="php"><![CDATA[
  117. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  118. // retrieve 10 messages at once
  119. $messages = $storageClient->peekMessages('testqueue', 10);
  120. foreach ($messages as $message) {
  121. echo $message->MessageText . "\r\n";
  122. }
  123. ]]></programlisting>
  124. </example>
  125. <para>
  126. Note that messages that are read using <methodname>peekMessages()</methodname> will
  127. not become invisible in the queue, nor can they be marked as processed using the
  128. <methodname>deleteMessage()</methodname> method. To do this, use
  129. <methodname>getMessages()</methodname> instead.
  130. </para>
  131. </sect3>
  132. </sect2>
  133. </sect1>