Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /modules/zendqueue.framework.html

Size:14910
Storage flags:no_autoload,compress/gzip (25%)

Framework — Zend Framework 2 2.4.2 documentation

Framework

The ZendQueue\Queue is a proxy that hides the details of the queue services. The queue services are represented by Zend\Queue\Adapter\<service>. For example, Zend\Queue\Adapter\Db is a queue that will use database tables to store and retrieve messages.

Below is an example for using database tables for a queuing system:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$options = array(
    'name'          => 'queue1',
    'driverOptions' => array(
        'host'      => '127.0.0.1',
        'port'      => '3306',
        'username'  => 'queue',
        'password'  => 'queue',
        'dbname'    => 'queue',
        'type'      => 'pdo_mysql'
    )
);

// Create a database queue.
// ZendQueue\Queue will prepend Zend\Queue\Adapter\ to 'Db' for the class name.
$queue = new Zend\Queue\Queue('Db', $options);

The ZendQueue\Queue constructor will create a Zend\Queue\Adapter\Db and initialize the adapter with the configuration settings.

The accepted configuration settings for each adapter are provided in the adapter notes.

ZendQueue\Queue returns messages using the class Zend\Queue\Message\Iterator, which is an implementation of SPL Iterator and Countable. Zend\Queue\Message\Iterator contains an array of Zend\Queue\Message objects.

1
2
3
4
$messages = $queue->receive(5);
foreach ($messages as $i => $message) {
    echo "$i) Message => ", $message->body, "\n";
}

Any exceptions thrown are of class Zend\Queue\Exception.

Introduction

ZendQueue\Queue is a proxy class that represents an adapter.

The send(), count($queue), and receive() methods are employed by each adapter to interact with queues.

The createQueue(), deleteQueue() methods are used to manage queues.

Commonality among adapters

The queue services supported by ZendQueue\Queue do not all support the same functions. For example, Zend\Queue\Adapter\Array, Zend\Queue\Adapter\Db, support all functions, while Zend\Queue\Adapter\Activemq does not support queue listing, queue deletion, or counting of messages.

You can determine what functions are supported by using Zend\Queue\Queue::isSupported() or Zend\Queue\Queue::getCapabilities().

  • createQueue()- create a queue

  • deleteQueue()- delete a queue

  • send()- send a message

    send() is not available in all adapters; the Zend\Queue\Adapter\Null does not support send().

  • receive()- receive messages

    receive() is not available in all adapters; the Zend\Queue\Adapter\Null does not support receive().

  • deleteMessage()- delete a message

  • count()- count the number of messages in a queue

  • isExists()- checks the existence of a queue

receive() methods are employed by each adapter to interact with queues.

The createQueue() and deleteQueue() methods are used to manage queues.

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 Framework 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