Adapters | Zend_Queue Programmer's Reference Guide | Stomp

# 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. class Custom_DbForUpdate extends Zend_Queue_Adapter_Db
2. {
3. /**
4. * @see code in tests/Zend/Queue/Custom/DbForUpdate.php
5. *
6. * Custom_DbForUpdate uses the SELECT ... FOR UPDATE to find it's rows.
7. * this is more likely to produce the wanted rows than the existing code.
8. *
9. * However, not all databases have SELECT ... FOR UPDATE as a feature.
10. *
11. * Note: this was later converted to be an option for Zend_Queue_Adapter_Db
12. *
13. * This code still serves as a good example.
14. */
15. }
17. $options = array (
18. 'name' => 'queue1',
19. 'driverOptions' => array (
20. 'host' => '127.0.0.1',
21. 'port' => '3306',
22. 'username' => 'queue',
23. 'password' => 'queue',
24. 'dbname' => 'queue',
25. 'type' => 'pdo_mysql'
26. )
27. );
29. $adapter = new Custom_DbForUpdate($options);
30. $queue = new Zend_Queue($adapter, $options);

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

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

or

1. $options = array (
2. 'name' => 'queue1',
3. 'namespace' => 'Custom',
4. 'driverOptions' => array (
5. 'host' => '127.0.0.1',
6. 'port' => '3306',
7. 'username' => 'queue',
8. 'password' => 'queue',
9. 'dbname' => 'queue',
10. 'type' => 'pdo_mysql'
11. )
12. );
13. $queue = new Zend_Queue('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. class Zend_Queue_Message
2. {
3. protected $_data = array ();
4. }

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 | Zend_Queue Programmer's Reference Guide | Stomp