Documentation

Zend_Service_WindowsAzure_Storage_Queue - Zend_Service

Zend_Service_WindowsAzure_Storage_Queue

The Queue service stores messages that may be read by any client who has access to the storage account.

A queue can contain an unlimited number of messages, each of which can be up to 8 KB in size. Messages are generally added to the end of the queue and retrieved from the front of the queue, although first in/first out (FIFO) behavior is not guaranteed. If you need to store messages larger than 8 KB, you can store message data as a queue or in a table and then store a reference to the data as a message in a queue.

Queue Storage is offered by Windows Azure as a REST API which is wrapped by the Zend_Service_WindowsAzure_Storage_Queue class in order to provide a native PHP interface to the storage account.

API Examples

This topic lists some examples of using the Zend_Service_WindowsAzure_Storage_Queue class. Other features are available in the download package, as well as a detailed API documentation of those features.

Creating a queue

Using the following code, a queue can be created on development storage.

Example #1 Creating a queue

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2. $result = $storageClient->createQueue('testqueue');
  3.  
  4. echo 'Queue name is: ' . $result->Name;

Deleting a queue

Using the following code, a queue can be removed from development storage.

Example #2 Deleting a queue

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2. $storageClient->deleteQueue('testqueue');

Adding a message to a queue

Using the following code, a message can be added to a queue on development storage. Note that the queue has already been created before.

Example #3 Adding a message to a queue

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2.  
  3. // 3600 = time-to-live of the message, if omitted defaults to 7 days
  4. $storageClient->putMessage('testqueue', 'This is a test message', 3600);

Reading a message from a queue

Using the following code, a message can be read from a queue on development storage. Note that the queue and message have already been created before.

Example #4 Reading a message from a queue

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2.  
  3. // retrieve 10 messages at once
  4. $messages = $storageClient->getMessages('testqueue', 10);
  5.  
  6. foreach ($messages as $message) {
  7.     echo $message->MessageText . "\r\n";
  8. }

The messages that are read using getMessages() will be invisible in the queue for 30 seconds, after which the messages will re-appear in the queue. To mark a message as processed and remove it from the queue, use the deleteMessage() method.

Example #5 Marking a message as processed

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2.  
  3. // retrieve 10 messages at once
  4. $messages = $storageClient->getMessages('testqueue', 10);
  5.  
  6. foreach ($messages as $message) {
  7.     echo $message . "\r\n";
  8.  
  9.     // Mark the message as processed
  10.     $storageClient->deleteMessage('testqueue', $message);
  11. }

Check if there are messages in a queue

Using the following code, a queue can be checked for new messages. Note that the queue and message have already been created before.

Example #6 Check if there are messages in a queue

  1. $storageClient = new Zend_Service_WindowsAzure_Storage_Queue();
  2.  
  3. // retrieve 10 messages at once
  4. $messages = $storageClient->peekMessages('testqueue', 10);
  5.  
  6. foreach ($messages as $message) {
  7.     echo $message->MessageText . "\r\n";
  8. }

Note that messages that are read using peekMessages() will not become invisible in the queue, nor can they be marked as processed using the deleteMessage() method. To do this, use getMessages() instead.

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts