Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /modules/zendqueue.custom.html

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

Customizing ZendQueue — Zend Framework 2 2.4.2 documentation

Customizing ZendQueue

Creating your own adapter

ZendQueue\Queue will accept any adapter that implements Zend\Queue\Adapter\AdapterAbstract. You can create your own adapter by extending one of the existing adapters, or the abstract class Zend\Queue\Adapter\AdapterAbstract. I suggest reviewing Zend\Queue\Adapter\Array as this adapter is the easiest to conceptualize.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Custom_DbForUpdate extends Zend\Queue\Adapter\Db
{
    /**
     * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
     *
     * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
     * this is more likely to produce the wanted rows than the existing code.
     *
     * However, not all databases have SELECT ... FOR UPDATE as a feature.
     *
     * Note: this was later converted to be an option for Zend\Queue\Adapter\Db
     *
     * This code still serves as a good example.
     */
}

$options = array(
    'name'          => 'queue1',
    'driverOptions' => array(
        'host'      => '127.0.0.1',
        'port'      => '3306',
        'username'  => 'queue',
        'password'  => 'queue',
        'dbname'    => 'queue',
        'type'      => 'pdo_mysql'
    )
);

$adapter = new Custom_DbForUpdate($options);
$queue = new Zend\Queue\Queue($adapter, $options);

You can also change the adapter on the fly as well.

1
2
3
4
$adapter = new MyCustom_Adapter($options);
$queue   = new Zend\Queue\Queue($options);
$queue->setAdapter($adapter);
echo "Adapter: ", get_class($queue->getAdapter()), "\n";

or

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$options = array(
    'name'           => 'queue1',
    'namespace'      => 'Custom',
    'driverOptions'  => array(
        'host'       => '127.0.0.1',
        'port'       => '3306',
        'username'   => 'queue',
        'password'   => 'queue',
        'dbname'     => 'queue',
        'type'       => 'pdo_mysql'
    )
);
$queue = new Zend\Queue\Queue('DbForUpdate', $config); // loads Custom_DbForUpdate

Creating your own message class

ZendQueue\Queue will also accept your own message class. Our variables start with an underscore. For example:

1
2
3
4
class Zend\Queue\Message
{
    protected $_data = array();
}

You can extend the existing messaging class. See the example code in tests/Zend/Queue/Custom/Message.php.

Creating your own message iterator class

ZendQueue\Queue will also accept your own message iterator class. The message iterator class is used to return messages from Zend\Queue\Adapter\Abstract::receive(). Zend\Queue\Abstract::receive() should always return a container class like Zend\Queue\Message\Iterator, even if there is only one message.

See the example filename in tests/Zend/Queue/Custom/Messages.php.

Creating your own queue class

ZendQueue\Queue can also be overloaded easily.

See the example filename in tests/Zend/Queue/Custom/Queue.php.

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 Customizing ZendQueue 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