Zend_Queue-Custom.xml 4.3 KB

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