Zend_Service_WindowsAzure_Queue.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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>
  18. <acronym>API</acronym> which is wrapped by the
  19. <classname>Zend_Service_WindowsAzure_Storage_Queue</classname> class in order to
  20. provide a native <acronym>PHP</acronym> interface to the storage account.
  21. </para>
  22. <sect2 id="zend.service.windowsazure.storage.queue.api">
  23. <title>API Examples</title>
  24. <para>
  25. This topic lists some examples of using the
  26. <classname>Zend_Service_WindowsAzure_Storage_Queue</classname> class. Other features
  27. are available in the download package, as well as a detailed <acronym>API</acronym>
  28. documentation of those features.
  29. </para>
  30. <sect3 id="zend.service.windowsazure.storage.queue.api.create-queue">
  31. <title>Creating a queue</title>
  32. <para>
  33. Using the following code, a queue can be created on development storage.
  34. </para>
  35. <example id="zend.service.windowsazure.storage.queue.api.create-queue.example">
  36. <title>Creating a queue</title>
  37. <programlisting language="php"><![CDATA[
  38. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  39. $result = $storageClient->createQueue('testqueue');
  40. echo 'Queue name is: ' . $result->Name;
  41. ]]></programlisting>
  42. </example>
  43. </sect3>
  44. <sect3 id="zend.service.windowsazure.storage.queue.api.delete-queue">
  45. <title>Deleting a queue</title>
  46. <para>
  47. Using the following code, a queue can be removed from development storage.
  48. </para>
  49. <example id="zend.service.windowsazure.storage.queue.api.delete-queue.example">
  50. <title>Deleting a queue</title>
  51. <programlisting language="php"><![CDATA[
  52. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  53. $storageClient->deleteQueue('testqueue');
  54. ]]></programlisting>
  55. </example>
  56. </sect3>
  57. <sect3 id="zend.service.windowsazure.storage.queue.api.storing-queue">
  58. <title>Adding a message to a queue</title>
  59. <para>
  60. Using the following code, a message can be added to a queue on development storage.
  61. Note that the queue has already been created before.
  62. </para>
  63. <example id="zend.service.windowsazure.storage.queue.api.storing-queue.example">
  64. <title>Adding a message to a queue</title>
  65. <programlisting language="php"><![CDATA[
  66. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  67. // 3600 = time-to-live of the message, if omitted defaults to 7 days
  68. $storageClient->putMessage('testqueue', 'This is a test message', 3600);
  69. ]]></programlisting>
  70. </example>
  71. </sect3>
  72. <sect3 id="zend.service.windowsazure.storage.queue.api.read-queue">
  73. <title>Reading a message from a queue</title>
  74. <para>
  75. Using the following code, a message can be read from a queue on development storage.
  76. Note that the queue and message have already been created before.
  77. </para>
  78. <example id="zend.service.windowsazure.storage.queue.api.read-queue.example">
  79. <title>Reading a message from a queue</title>
  80. <programlisting language="php"><![CDATA[
  81. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  82. // retrieve 10 messages at once
  83. $messages = $storageClient->getMessages('testqueue', 10);
  84. foreach ($messages as $message) {
  85. echo $message->MessageText . "\r\n";
  86. }
  87. ]]></programlisting>
  88. </example>
  89. <para>
  90. The messages that are read using <methodname>getMessages()</methodname> will be
  91. invisible in the queue for 30 seconds, after which the messages will re-appear in
  92. the queue. To mark a message as processed and remove it from the queue, use the
  93. <methodname>deleteMessage()</methodname> method.
  94. </para>
  95. <example id="zend.service.windowsazure.storage.queue.api.read-queue.processexample">
  96. <title>Marking a message as processed</title>
  97. <programlisting language="php"><![CDATA[
  98. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  99. // retrieve 10 messages at once
  100. $messages = $storageClient->getMessages('testqueue', 10);
  101. foreach ($messages as $message) {
  102. echo $message . "\r\n";
  103. // Mark the message as processed
  104. $storageClient->deleteMessage('testqueue', $message);
  105. }
  106. ]]></programlisting>
  107. </example>
  108. </sect3>
  109. <sect3 id="zend.service.windowsazure.storage.queue.api.peek-queue">
  110. <title>Check if there are messages in a queue</title>
  111. <para>
  112. Using the following code, a queue can be checked for new messages. Note that the
  113. queue and message have already been created before.
  114. </para>
  115. <example id="zend.service.windowsazure.storage.queue.api.peek-queue.example">
  116. <title>Check if there are messages in a queue</title>
  117. <programlisting language="php"><![CDATA[
  118. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  119. // retrieve 10 messages at once
  120. $messages = $storageClient->peekMessages('testqueue', 10);
  121. foreach ($messages as $message) {
  122. echo $message->MessageText . "\r\n";
  123. }
  124. ]]></programlisting>
  125. </example>
  126. <para>
  127. Note that messages that are read using <methodname>peekMessages()</methodname> will
  128. not become invisible in the queue, nor can they be marked as processed using the
  129. <methodname>deleteMessage()</methodname> method. To do this, use
  130. <methodname>getMessages()</methodname> instead.
  131. </para>
  132. </sect3>
  133. </sect2>
  134. </sect1>