Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /modules/zendservice.windows-azure.queue.html

Size:18544
Storage flags:no_autoload,compress/gzip (22%)

ZendService\WindowsAzure\StorageQueue — Zend Framework 2 2.4.2 documentation

ZendService\WindowsAzure\StorageQueue

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 ZendService\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 ZendService\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.

Creating a queue

1
2
3
4
$storageClient = new ZendService\WindowsAzure\Storage\Queue();
$result = $storageClient->createQueue('testqueue');

echo 'Queue name is: ' . $result->Name;

Deleting a queue

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

Deleting a queue

1
2
$storageClient = new ZendService\WindowsAzure\Storage\Queue();
$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.

Adding a message to a queue

1
2
3
4
$storageClient = new ZendService\WindowsAzure\Storage\Queue();

// 3600 = time-to-live of the message, if omitted defaults to 7 days
$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.

Reading a message from a queue

1
2
3
4
5
6
7
8
$storageClient = new ZendService\WindowsAzure\Storage\Queue();

// retrieve 10 messages at once
$messages = $storageClient->getMessages('testqueue', 10);

foreach ($messages as $message) {
    echo $message->MessageText . "\r\n";
}

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.

Marking a message as processed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$storageClient = new ZendService\WindowsAzure\Storage\Queue();

// retrieve 10 messages at once
$messages = $storageClient->getMessages('testqueue', 10);

foreach ($messages as $message) {
    echo $message . "\r\n";

    // Mark the message as processed
    $storageClient->deleteMessage('testqueue', $message);
}

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.

Check if there are messages in a queue

1
2
3
4
5
6
7
8
$storageClient = new ZendService\WindowsAzure\Storage\Queue();

// retrieve 10 messages at once
$messages = $storageClient->peekMessages('testqueue', 10);

foreach ($messages as $message) {
    echo $message->MessageText . "\r\n";
}

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.

Table Of Contents

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to ZendService\WindowsAzure\StorageQueue on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.

For more information about the PHK package format: http://phk.tekwire.net