1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.queue.adapters">
4 <title>Adapters</title>
7 <classname>Zend_Queue</classname> supports all queues implementing the
8 interface <classname>Zend_Queue_Adapter_AdapterInterface</classname>.
9 The following Message Queue services are supported:
15 <ulink url="http://activemq.apache.org/">Apache ActiveMQ</ulink>.
21 A database driven queue via <classname>Zend_Db</classname>.
27 A <ulink url="http://memcachedb.org/memcacheq/">MemcacheQ</ulink>
28 queue driven via <classname>Memcache</classname>.
34 <ulink url="http://www.zend.com/en/products/platform/">Zend Platform's</ulink> Job
41 A local array. Useful for unit testing.
46 <note id="zend.queue.adapters.limitations">
47 <title>Limitations</title>
50 Message transaction handling is not supported.
54 <sect2 id="zend.queue.adapters.configuration">
55 <title>Specific Adapters - Configuration settings</title>
58 If a default setting is indicated then the parameter is optional.
59 If a default setting is not specified then the parameter is
63 <sect3 id="zend.queue.adapters.configuration.activemq">
64 <title>Apache ActiveMQ - Zend_Queue_Adapter_Activemq</title>
67 Options listed here are known requirements. Not all
68 messaging servers require username or password.
74 <emphasis>$options['name'] = '/temp/queue1';</emphasis>
78 This is the name of the queue that you wish to start
85 <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
89 <emphasis>$options['driverOptions']['host'] = '127.0.0.1';</emphasis>
93 You may set host to an IP address or a hostname.
97 Default setting for host is '127.0.0.1'.
103 <emphasis>$options['driverOptions']['port'] = 61613;</emphasis>
106 <para>Default setting for port is 61613.</para>
111 <emphasis>$options['driverOptions']['username'] = 'username';</emphasis>
115 Optional for some messaging servers. Read the manual
116 for your messaging server.
122 <emphasis>$options['driverOptions']['password'] = 'password';</emphasis>
126 Optional for some messaging servers. Read the manual
127 for your messaging server.
133 <emphasis>$options['driverOptions']['timeout_sec'] = 2;</emphasis>
137 <emphasis>$options['driverOptions']['timeout_usec'] = 0;</emphasis>
141 This is the amount of time that
142 <classname>Zend_Queue_Adapter_Activemq</classname> will wait for
143 read activity on a socket before returning no messages.
149 <sect3 id="zend.queue.adapters.configuration.Db">
150 <title>Db - Zend_Queue_Adapter_Db</title>
153 Driver options are checked for a few required options such
154 as <emphasis>type</emphasis>, <emphasis>host</emphasis>,
155 <emphasis>username</emphasis>, <emphasis>password</emphasis>,
156 and <emphasis>dbname</emphasis>. You may pass along
157 additional parameters for <methodname>Zend_DB::factory()</methodname> as parameters
158 in <varname>$options['driverOptions']</varname>. An example of an additional
159 option not listed here, but could be passed would be <emphasis>port</emphasis>.
162 <programlisting language="php"><![CDATA[
164 'driverOptions' => array(
165 'host' => 'db1.domain.tld',
166 'username' => 'my_username',
167 'password' => 'my_password',
168 'dbname' => 'messaging',
169 'type' => 'pdo_mysql',
170 'port' => 3306, // optional parameter.
173 // use Zend_Db_Select for update, not all databases can support this
175 Zend_Db_Select::FOR_UPDATE => true
179 // Create a database queue.
180 $queue = new Zend_Queue('Db', $options);
186 <emphasis>$options['name'] = 'queue1';</emphasis>
190 This is the name of the queue that you wish to start using. (Required)
196 <emphasis>$options['driverOptions']['type'] = 'Pdo';</emphasis>
200 <emphasis>type</emphasis> is the adapter you wish to have
201 <methodname>Zend_Db::factory()</methodname> use. This is
202 the first parameter for the
203 <methodname>Zend_Db::factory()</methodname> class
210 <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
214 <emphasis>$options['driverOptions']['host'] = '127.0.0.1';</emphasis>
217 <para>You may set host to an IP address or a hostname.</para>
219 <para>Default setting for host is '127.0.0.1'.</para>
224 <emphasis>$options['driverOptions']['username'] = 'username';</emphasis>
230 <emphasis>$options['driverOptions']['password'] = 'password';</emphasis>
236 <emphasis>$options['driverOptions']['dbname'] = 'dbname';</emphasis>
240 The database name that you have created the required tables for.
241 See the notes section below.
247 <sect3 id="zend.queue.adapters.configuration.memcacheq">
248 <title>MemcacheQ - Zend_Queue_Adapter_Memcacheq</title>
253 <emphasis>$options['name'] = 'queue1';</emphasis>
257 This is the name of the queue that you wish to start using. (Required)
263 <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
267 <emphasis>$options['driverOptions']['host'] = '127.0.0.1;'</emphasis>
270 <para>You may set host to an IP address or a hostname.</para>
272 <para>Default setting for host is '127.0.0.1'.</para>
277 <emphasis>$options['driverOptions']['port'] = 22201;</emphasis>
280 <para>The default setting for port is 22201.</para>
285 <sect3 id="zend.queue.adapters.configuration.platformjq">
286 <title>Zend Platform Job Queue - Zend_Queue_Adapter_PlatformJobQueue</title>
291 <emphasis>$options['daemonOptions']['host'] = '127.0.0.1:10003';</emphasis>
295 The hostname and port corresponding to the Zend Platform Job Queue daemon
296 you will use. (Required)
302 <emphasis>$options['daemonOptions']['password'] = '1234';</emphasis>
306 The password required for accessing the Zend Platform Job Queue daemon.
313 <sect3 id="zend.queue.adapters.configuration.array">
314 <title>Array - Zend_Queue_Adapter_Array</title>
319 <emphasis>$options['name'] = 'queue1';</emphasis>
323 This is the name of the queue that you wish to start using. (Required)
330 <sect2 id="zend.queue.adapters.notes">
331 <title>Notes for Specific Adapters</title>
333 <para>The following adapters have notes:</para>
335 <sect3 id="zend.queue.adapters.notes.activemq">
336 <title>Apache ActiveMQ</title>
339 Visibility duration for
340 <classname>Zend_Queue_Adapter_Activemq</classname> is not
345 While Apache's ActiveMQ will support multiple subscriptions, the
346 <classname>Zend_Queue</classname> does not. You must create a
347 new <classname>Zend_Queue</classname> object for each individual
352 ActiveMQ queue/topic names must begin with one of:
358 <filename>/queue/</filename>
364 <filename>/topic/</filename>
370 <filename>/temp-queue/</filename>
376 <filename>/temp-topic/</filename>
382 For example: <filename>/queue/testing</filename>
386 The following functions are not supported:
392 <methodname>create()</methodname> - create queue.
393 Calling this function will throw an exception.
399 <methodname>delete()</methodname> - delete queue.
400 Calling this function will throw an exception.
406 <methodname>getQueues()</methodname> - list queues.
407 Calling this function will throw an exception.
413 <sect3 id="zend.queue.adapters.notes.zend_db">
414 <title>Zend_Db</title>
417 The database <emphasis>CREATE TABLE ( ... )</emphasis> <acronym>SQL</acronym>
418 statement can be found in <filename>Zend/Queue/Adapter/Db/mysql.sql</filename>.
422 <sect3 id="zend.queue.adapters.notes.memcacheQ">
423 <title>MemcacheQ</title>
426 Memcache can be downloaded from <ulink
427 url="http://www.danga.com/memcached/">http://www.danga.com/memcached/</ulink>.
431 MemcacheQ can be downloaded from <ulink
432 url="http://memcachedb.org/memcacheq/">http://memcachedb.org/memcacheq/</ulink>.
438 <methodname>deleteMessage()</methodname> - Messages are deleted upon
439 reception from the queue. Calling this function would
440 have no effect. Calling this function will throw an
447 <methodname>count()</methodname> or <methodname>count($adapter)</methodname>
448 - MemcacheQ does not support a method for counting the number of items in
449 a queue. Calling this function will throw an error.
455 <sect3 id="zend.queue.adapters.notes.platformjq">
456 <title>Zend Platform Job Queue</title>
459 Job Queue is a feature of Zend Platform's Enterprise Solution offering. It is not a
460 traditional message queue, and instead allows you to queue a script to execute,
461 along with the parameters you wish to pass to it. You can find out more about Job
462 Queue <ulink url="http://www.zend.com/en/products/platform/">on the zend.com
467 The following is a list of methods where this adapter's behavior diverges from the
474 <methodname>create()</methodname> - Zend Platform does not have the concept
475 of discrete queues; instead, it allows administrators to provide scripts for
476 processing jobs. Since adding new scripts is restricted to the
477 administration interface, this method simply throws an exception indicating
478 the action is forbidden.
484 <methodname>isExists()</methodname> - Just like
485 <methodname>create()</methodname>, since Job Queue does not have a notion of
486 named queues, this method throws an exception when invoked.
492 <methodname>delete()</methodname> - similar to
493 <methodname>create()</methodname>, deletion of JQ scripts is not possible
494 except via the admin interface; this method raises an exception.
500 <methodname>getQueues()</methodname> - Zend Platform does not allow
501 introspection into the attached job handling scripts via the
502 <acronym>API</acronym>. This method throws an exception.
508 <methodname>count()</methodname> - returns the total number of jobs
509 currently active in the Job Queue.
515 <methodname>send()</methodname> - this method is perhaps the one method that
516 diverges most from other adapters. The <varname>$message</varname> argument
517 may be one of three possible types, and will operate differently based on
524 <acronym>string</acronym> - the name of a script registered with Job
525 Queue to invoke. If passed in this way, no arguments are provided to
532 <acronym>array</acronym> - an array of values with which to
533 configure a <classname>ZendApi_Job</classname> object. These may
534 include the following:
540 <varname>script</varname> - the name of the Job Queue script
541 to invoke. (Required)
547 <varname>priority</varname> - the job priority to use when
548 registering with the queue.
554 <varname>name</varname> - a short string describing the job.
560 <varname>predecessor</varname> - the ID of a job on which
561 this one depends, and which must be executed before this one
568 <varname>preserved</varname> - whether or not to retain the
569 job within the Job Queue history. By default, off; pass a
570 <constant>TRUE</constant> value to retain it.
576 <varname>user_variables</varname> - an associative array of
577 all variables you wish to have in scope during job execution
578 (similar to named arguments).
584 <varname>interval</varname> - how often, in seconds, the job
585 should run. By default, this is set to 0, indicating it
586 should run once, and once only.
592 <varname>end_time</varname> - an expiry time, past which the
593 job should not run. If the job was set to run only once,
594 and <varname>end_time</varname> has passed, then the job
595 will not be executed. If the job was set to run on an
596 interval, it will not execute again once
597 <varname>end_time</varname> has passed.
603 <varname>schedule_time</varname> - a <acronym>UNIX</acronym>
604 timestamp indicating when to run the job; by default, 0,
605 indicating the job should run as soon as possible.
611 <varname>application_id</varname> - the application
612 identifier of the job. By default, this is
613 <constant>NULL</constant>, indicating that one will be
614 automatically assigned by the queue, if the queue was
615 assigned an application ID.
621 As noted, only the <varname>script</varname> argument is required;
622 all others are simply available to allow passing more fine-grained
623 detail on how and when to run the job.
629 <classname>ZendApi_Job</classname> - finally, you may simply pass a
630 <classname>ZendApi_Job</classname> instance, and it will be passed
631 along to Platform's Job Queue.
637 In all instances, <methodname>send()</methodname> returns a
638 <classname>Zend_Queue_Message_PlatformJob</classname> object, which provides
639 access to the <classname>ZendApi_Job</classname> object used to communicate
646 <methodname>receive()</methodname> - retrieves a list of active jobs from
647 Job Queue. Each job in the returned set will be an instance of
648 <classname>Zend_Queue_Message_PlatformJob</classname>.
654 <methodname>deleteMessage()</methodname> - since this adapter only works
655 with Job Queue, this method expects the provided <varname>$message</varname>
656 to be a <classname>Zend_Queue_Message_PlatformJob</classname> instance, and
657 will throw an exception otherwise.
663 <sect3 id="zend.queue.adapters.notes.array">
664 <title>Array (local)</title>
667 The Array queue is a <acronym>PHP</acronym> <methodname>array()</methodname>
668 in local memory. The <classname>Zend_Queue_Adapter_Array</classname> is good for