1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.queue.custom">
4 <title>Customizing Zend_Queue</title>
6 <sect2 id="zend.queue.custom.adapter">
7 <title>Creating your own adapter</title>
10 <classname>Zend_Queue</classname> will accept any adapter that
12 <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. You can
13 create your own adapter by extending one of the existing adapters,
15 <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. I
16 suggest reviewing <classname>Zend_Queue_Adapter_Array</classname> as
17 this adapter is the easiest to conceptualize.
20 <programlisting language="php"><![CDATA[
21 class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
24 * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
26 * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
27 * this is more likely to produce the wanted rows than the existing code.
29 * However, not all databases have SELECT ... FOR UPDATE as a feature.
31 * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
33 * This code still serves as a good example.
39 'driverOptions' => array(
40 'host' => '127.0.0.1',
42 'username' => 'queue',
43 'password' => 'queue',
49 $adapter = new Custom_DbForUpdate($options);
50 $queue = new Zend_Queue($adapter, $options);
54 You can also change the adapter on the fly as well.
57 <programlisting language="php"><![CDATA[
58 $adapter = new MyCustom_Adapter($options);
59 $queue = new Zend_Queue($options);
60 $queue->setAdapter($adapter);
61 echo "Adapter: ", get_class($queue->getAdapter()), "\n";
66 <programlisting language="php"><![CDATA[
69 'namespace' => 'Custom',
70 'driverOptions' => array(
71 'host' => '127.0.0.1',
73 'username' => 'queue',
74 'password' => 'queue',
79 $queue = new Zend_Queue('DbForUpdate', $config); // loads Custom_DbForUpdate
83 <sect2 id="zend.queue.custom.message">
84 <title>Creating your own message class</title>
87 <classname>Zend_Queue</classname> will also accept your own message class.
88 Our variables start with an underscore. For example:
91 <programlisting language="php"><![CDATA[
92 class Zend_Queue_Message
94 protected $_data = array();
99 You can extend the existing messaging class. See the example code in
100 <filename>tests/Zend/Queue/Custom/Message.php</filename>.
104 <sect2 id="zend.queue.custom-iterator">
105 <title>Creating your own message iterator class</title>
108 <classname>Zend_Queue</classname> will also accept your own message
109 iterator class. The message iterator class is used to return
111 <methodname>Zend_Queue_Adapter_Abstract::recieve()</methodname>.
112 <methodname>Zend_Queue_Abstract::receive()</methodname> should always
113 return a container class like
114 <classname>Zend_Queue_Message_Iterator</classname>, even if there is
119 See the example filename in
120 <filename>tests/Zend/Queue/Custom/Messages.php</filename>.
124 <sect2 id="zend.queue.custom.queue">
125 <title>Creating your own queue class </title>
128 <classname>Zend_Queue</classname> can also be overloaded easily.
132 See the example filename in <filename>tests/Zend/Queue/Custom/Queue.php</filename>.