Adapters

Customizing Zend_Queue

Creating your own adapter

Zend_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. span style="color: #808080; font-style: italic;">/**
  2.      * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
  3.      *
  4.      * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
  5.      * this is more likely to produce the wanted rows than the existing code.
  6.      *
  7.      * However, not all databases have SELECT ... FOR UPDATE as a feature.
  8.      *
  9.      * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
  10.      *
  11.      * This code still serves as a good example.
  12.      */'name'          => 'queue1',
  13.     'driverOptions''host'      => '127.0.0.1',
  14.         'port'      => '3306',
  15.         'username'  => 'queue',
  16.         'password'  => 'queue',
  17.         'dbname'    => 'queue',
  18.         'type'      => 'pdo_mysql'

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

  1. span style="color: #ff0000;">"Adapter: ""\n";

or

  1. span style="color: #ff0000;">'name'           => 'queue1',
  2.     'namespace'      => 'Custom',
  3.     'driverOptions''host'       => '127.0.0.1',
  4.         'port'       => '3306',
  5.         'username'   => 'queue',
  6.         'password'   => 'queue',
  7.         'dbname'     => 'queue',
  8.         'type'       => 'pdo_mysql''DbForUpdate', $config); // loads Custom_DbForUpdate

Creating your own message class

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

  1.  

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

Creating your own message iterator class

Zend_Queue will also accept your own message iterator class. The message iterator class is used to return messages from Zend_Queue_Adapter_Abstract::recieve(). 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

Zend_Queue can also be overloaded easily.

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


Adapters