Zend_Queue-Custom.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.queue.custom">
  4. <title>Customizing Zend_Queue</title>
  5. <sect2 id="zend.queue.custom.adapter">
  6. <title>Creating your own adapter</title>
  7. <para>
  8. <classname>Zend_Queue</classname> will accept any adapter that
  9. implements
  10. <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. You can
  11. create your own adapter by extending one of the existing adapters,
  12. or the abstract class
  13. <classname>Zend_Queue_Adapter_AdapterAbstract</classname>. I
  14. suggest reviewing <classname>Zend_Queue_Adapter_Array</classname> as
  15. this adapter is the easiest to conceptualize.
  16. </para>
  17. <programlisting language="php"><![CDATA[
  18. class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
  19. {
  20. /**
  21. * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
  22. *
  23. * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
  24. * this is more likely to produce the wanted rows than the existing code.
  25. *
  26. * However, not all databases have SELECT ... FOR UPDATE as a feature.
  27. *
  28. * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
  29. *
  30. * This code still serves as a good example.
  31. */
  32. }
  33. $options = array(
  34. 'name' => 'queue1',
  35. 'driverOptions' => array(
  36. 'host' => '127.0.0.1',
  37. 'port' => '3306',
  38. 'username' => 'queue',
  39. 'password' => 'queue',
  40. 'dbname' => 'queue',
  41. 'type' => 'pdo_mysql'
  42. )
  43. );
  44. $adapter = new Custom_DbForUpdate($options);
  45. $queue = new Zend_Queue($adapter, $options);
  46. ]]></programlisting>
  47. <para>
  48. You can also change the adapter on the fly as well.
  49. </para>
  50. <programlisting language="php"><![CDATA[
  51. $adapter = new MyCustom_Adapter($options);
  52. $queue = new Zend_Queue($options);
  53. $queue->setAdapter($adapter);
  54. echo "Adapter: ", get_class($queue->getAdapter()), "\n";
  55. ]]></programlisting>
  56. <para>or</para>
  57. <programlisting language="php"><![CDATA[
  58. $options = array(
  59. 'name' => 'queue1',
  60. 'namespace' => 'Custom',
  61. 'driverOptions' => array(
  62. 'host' => '127.0.0.1',
  63. 'port' => '3306',
  64. 'username' => 'queue',
  65. 'password' => 'queue',
  66. 'dbname' => 'queue',
  67. 'type' => 'pdo_mysql'
  68. )
  69. );
  70. $queue = new Zend_Queue('DbForUpdate', $config); // loads Custom_DbForUpdate
  71. ]]></programlisting>
  72. </sect2>
  73. <sect2 id="zend.queue.custom.message">
  74. <title>Creating your own message class</title>
  75. <para>
  76. <classname>Zend_Queue</classname> will also accept your own message class.
  77. Our variables start with an underscore. For example:
  78. </para>
  79. <programlisting language="php"><![CDATA[
  80. class Zend_Queue_Message
  81. {
  82. protected $_data = array();
  83. }
  84. ]]></programlisting>
  85. <para>
  86. You can extend the existing messaging class. See the example code in
  87. <filename>tests/Zend/Queue/Custom/Message.php</filename>.
  88. </para>
  89. </sect2>
  90. <sect2 id="zend.queue.custom-iterator">
  91. <title>Creating your own message iterator class</title>
  92. <para>
  93. <classname>Zend_Queue</classname> will also accept your own message
  94. iterator class. The message iterator class is used to return
  95. messages from
  96. <methodname>Zend_Queue_Adapter_Abstract::recieve()</methodname>.
  97. <methodname>Zend_Queue_Abstract::receive()</methodname> should always
  98. return a container class like
  99. <classname>Zend_Queue_Message_Iterator</classname>, even if there is
  100. only one message.
  101. </para>
  102. <para>
  103. See the example filename in
  104. <filename>tests/Zend/Queue/Custom/Messages.php</filename>.
  105. </para>
  106. </sect2>
  107. <sect2 id="zend.queue.custom.queue">
  108. <title>Creating your own queue class </title>
  109. <para>
  110. <classname>Zend_Queue</classname> can also be overloaded easily.
  111. </para>
  112. <para>
  113. See the example filename in <filename>tests/Zend/Queue/Custom/Queue.php</filename>.
  114. </para>
  115. </sect2>
  116. </sect1>