Zend_Queue-Adapters.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.queue.adapters">
  4. <title>Adapters</title>
  5. <para>
  6. <classname>Zend_Queue</classname> supports all queues implementing the
  7. interface <classname>Zend_Queue_Adapter_AdapterInterface</classname>.
  8. The following Message Queue services are supported:
  9. </para>
  10. <itemizedlist>
  11. <listitem>
  12. <para>
  13. <ulink url="http://activemq.apache.org/">Apache ActiveMQ</ulink>.
  14. </para>
  15. </listitem>
  16. <listitem>
  17. <para>
  18. A database driven queue via <classname>Zend_Db</classname>.
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>
  23. A <ulink url="http://memcachedb.org/memcacheq/">MemcacheQ</ulink>
  24. queue driven via <classname>Memcache</classname>.
  25. </para>
  26. </listitem>
  27. <listitem>
  28. <para>
  29. <ulink url="http://www.zend.com/en/products/platform/">Zend Platform's</ulink> Job
  30. Queue.
  31. </para>
  32. </listitem>
  33. <listitem>
  34. <para>
  35. A local array. Useful for unit testing.
  36. </para>
  37. </listitem>
  38. </itemizedlist>
  39. <note id="zend.queue.adapters.limitations">
  40. <title>Limitations</title>
  41. <para>
  42. Message transaction handling is not supported.
  43. </para>
  44. </note>
  45. <sect2 id="zend.queue.adapters.configuration">
  46. <title>Specific Adapters - Configuration settings</title>
  47. <para>
  48. If a default setting is indicated then the parameter is optional.
  49. If a default setting is not specified then the parameter is
  50. required.
  51. </para>
  52. <sect3 id="zend.queue.adapters.configuration.activemq">
  53. <title>Apache ActiveMQ - Zend_Queue_Adapter_Activemq</title>
  54. <para>
  55. Options listed here are known requirements. Not all
  56. messaging servers require username or password.
  57. </para>
  58. <itemizedlist>
  59. <listitem>
  60. <para>
  61. <emphasis>$options['name'] = '/temp/queue1';</emphasis>
  62. </para>
  63. <para>
  64. This is the name of the queue that you wish to start
  65. using. (Required)
  66. </para>
  67. </listitem>
  68. <listitem>
  69. <para>
  70. <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
  71. </para>
  72. <para>
  73. <emphasis>$options['driverOptions']['host'] = '127.0.0.1';</emphasis>
  74. </para>
  75. <para>
  76. You may set host to an IP address or a hostname.
  77. </para>
  78. <para>
  79. Default setting for host is '127.0.0.1'.
  80. </para>
  81. </listitem>
  82. <listitem>
  83. <para>
  84. <emphasis>$options['driverOptions']['port'] = 61613;</emphasis>
  85. </para>
  86. <para>Default setting for port is 61613.</para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <emphasis>$options['driverOptions']['username'] = 'username';</emphasis>
  91. </para>
  92. <para>
  93. Optional for some messaging servers. Read the manual
  94. for your messaging server.
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. <emphasis>$options['driverOptions']['password'] = 'password';</emphasis>
  100. </para>
  101. <para>
  102. Optional for some messaging servers. Read the manual
  103. for your messaging server.
  104. </para>
  105. </listitem>
  106. <listitem>
  107. <para>
  108. <emphasis>$options['driverOptions']['timeout_sec'] = 2;</emphasis>
  109. </para>
  110. <para>
  111. <emphasis>$options['driverOptions']['timeout_usec'] = 0;</emphasis>
  112. </para>
  113. <para>
  114. This is the amount of time that
  115. <classname>Zend_Queue_Adapter_Activemq</classname> will wait for
  116. read activity on a socket before returning no messages.
  117. </para>
  118. </listitem>
  119. </itemizedlist>
  120. </sect3>
  121. <sect3 id="zend.queue.adapters.configuration.Db">
  122. <title>Db - Zend_Queue_Adapter_Db</title>
  123. <para>
  124. Driver options are checked for a few required options such
  125. as <emphasis>type</emphasis>, <emphasis>host</emphasis>,
  126. <emphasis>username</emphasis>, <emphasis>password</emphasis>,
  127. and <emphasis>dbname</emphasis>. You may pass along
  128. additional parameters for <methodname>Zend_DB::factory()</methodname> as parameters
  129. in <varname>$options['driverOptions']</varname>. An example of an additional
  130. option not listed here, but could be passed would be <emphasis>port</emphasis>.
  131. </para>
  132. <programlisting language="php"><![CDATA[
  133. $options = array(
  134. 'driverOptions' => array(
  135. 'host' => 'db1.domain.tld',
  136. 'username' => 'my_username',
  137. 'password' => 'my_password',
  138. 'dbname' => 'messaging',
  139. 'type' => 'pdo_mysql',
  140. 'port' => 3306, // optional parameter.
  141. ),
  142. 'options' => array(
  143. // use Zend_Db_Select for update, not all databases can support this
  144. // feature.
  145. Zend_Db_Select::FOR_UPDATE => true
  146. )
  147. );
  148. // Create a database queue.
  149. $queue = new Zend_Queue('Db', $options);
  150. ]]></programlisting>
  151. <itemizedlist>
  152. <listitem>
  153. <para>
  154. <emphasis>$options['name'] = 'queue1';</emphasis>
  155. </para>
  156. <para>
  157. This is the name of the queue that you wish to start using. (Required)
  158. </para>
  159. </listitem>
  160. <listitem>
  161. <para>
  162. <emphasis>$options['driverOptions']['type'] = 'Pdo';</emphasis>
  163. </para>
  164. <para>
  165. <emphasis>type</emphasis> is the adapter you wish to have
  166. <methodname>Zend_Db::factory()</methodname> use. This is
  167. the first parameter for the
  168. <methodname>Zend_Db::factory()</methodname> class
  169. method call.
  170. </para>
  171. </listitem>
  172. <listitem>
  173. <para>
  174. <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
  175. </para>
  176. <para>
  177. <emphasis>$options['driverOptions']['host'] = '127.0.0.1';</emphasis>
  178. </para>
  179. <para>You may set host to an IP address or a hostname.</para>
  180. <para>Default setting for host is '127.0.0.1'.</para>
  181. </listitem>
  182. <listitem>
  183. <para>
  184. <emphasis>$options['driverOptions']['username'] = 'username';</emphasis>
  185. </para>
  186. </listitem>
  187. <listitem>
  188. <para>
  189. <emphasis>$options['driverOptions']['password'] = 'password';</emphasis>
  190. </para>
  191. </listitem>
  192. <listitem>
  193. <para>
  194. <emphasis>$options['driverOptions']['dbname'] = 'dbname';</emphasis>
  195. </para>
  196. <para>
  197. The database name that you have created the required tables for.
  198. See the notes section below.
  199. </para>
  200. </listitem>
  201. </itemizedlist>
  202. </sect3>
  203. <sect3 id="zend.queue.adapters.configuration.memcacheq">
  204. <title>MemcacheQ - Zend_Queue_Adapter_Memcacheq</title>
  205. <itemizedlist>
  206. <listitem>
  207. <para>
  208. <emphasis>$options['name'] = 'queue1';</emphasis>
  209. </para>
  210. <para>
  211. This is the name of the queue that you wish to start using. (Required)
  212. </para>
  213. </listitem>
  214. <listitem>
  215. <para>
  216. <emphasis>$options['driverOptions']['host'] = 'host.domain.tld';</emphasis>
  217. </para>
  218. <para>
  219. <emphasis>$options['driverOptions']['host'] = '127.0.0.1;'</emphasis>
  220. </para>
  221. <para>You may set host to an IP address or a hostname.</para>
  222. <para>Default setting for host is '127.0.0.1'.</para>
  223. </listitem>
  224. <listitem>
  225. <para>
  226. <emphasis>$options['driverOptions']['port'] = 22201;</emphasis>
  227. </para>
  228. <para>The default setting for port is 22201.</para>
  229. </listitem>
  230. </itemizedlist>
  231. </sect3>
  232. <sect3 id="zend.queue.adapters.configuration.platformjq">
  233. <title>Zend Platform Job Queue - Zend_Queue_Adapter_PlatformJobQueue</title>
  234. <itemizedlist>
  235. <listitem>
  236. <para>
  237. <emphasis>$options['daemonOptions']['host'] = '127.0.0.1:10003';</emphasis>
  238. </para>
  239. <para>
  240. The hostname and port corresponding to the Zend Platform Job Queue daemon
  241. you will use. (Required)
  242. </para>
  243. </listitem>
  244. <listitem>
  245. <para>
  246. <emphasis>$options['daemonOptions']['password'] = '1234';</emphasis>
  247. </para>
  248. <para>
  249. The password required for accessing the Zend Platform Job Queue daemon.
  250. (Required)
  251. </para>
  252. </listitem>
  253. </itemizedlist>
  254. </sect3>
  255. <sect3 id="zend.queue.adapters.configuration.array">
  256. <title>Array - Zend_Queue_Adapter_Array</title>
  257. <itemizedlist>
  258. <listitem>
  259. <para>
  260. <emphasis>$options['name'] = 'queue1';</emphasis>
  261. </para>
  262. <para>
  263. This is the name of the queue that you wish to start using. (Required)
  264. </para>
  265. </listitem>
  266. </itemizedlist>
  267. </sect3>
  268. </sect2>
  269. <sect2 id="zend.queue.adapters.notes">
  270. <title>Notes for Specific Adapters</title>
  271. <para>The following adapters have notes:</para>
  272. <sect3 id="zend.queue.adapters.notes.activemq">
  273. <title>Apache ActiveMQ</title>
  274. <para>
  275. Visibility duration for
  276. <classname>Zend_Queue_Adapter_Activemq</classname> is not
  277. available.
  278. </para>
  279. <para>
  280. While Apache's ActiveMQ will support multiple subscriptions, the
  281. <classname>Zend_Queue</classname> does not. You must create a
  282. new <classname>Zend_Queue</classname> object for each individual
  283. subscription.
  284. </para>
  285. <para>
  286. ActiveMQ queue/topic names must begin with one of:
  287. </para>
  288. <itemizedlist>
  289. <listitem>
  290. <para>
  291. <filename>/queue/</filename>
  292. </para>
  293. </listitem>
  294. <listitem>
  295. <para>
  296. <filename>/topic/</filename>
  297. </para>
  298. </listitem>
  299. <listitem>
  300. <para>
  301. <filename>/temp-queue/</filename>
  302. </para>
  303. </listitem>
  304. <listitem>
  305. <para>
  306. <filename>/temp-topic/</filename>
  307. </para>
  308. </listitem>
  309. </itemizedlist>
  310. <para>
  311. For example: <filename>/queue/testing</filename>
  312. </para>
  313. <para>
  314. The following functions are not supported:
  315. </para>
  316. <itemizedlist>
  317. <listitem>
  318. <para>
  319. <methodname>create()</methodname> - create queue.
  320. Calling this function will throw an exception.
  321. </para>
  322. </listitem>
  323. <listitem>
  324. <para>
  325. <methodname>delete()</methodname> - delete queue.
  326. Calling this function will throw an exception.
  327. </para>
  328. </listitem>
  329. <listitem>
  330. <para>
  331. <methodname>getQueues()</methodname> - list queues.
  332. Calling this function will throw an exception.
  333. </para>
  334. </listitem>
  335. </itemizedlist>
  336. </sect3>
  337. <sect3 id="zend.queue.adapters.notes.zend_db">
  338. <title>Zend_Db</title>
  339. <para>
  340. The database <emphasis>CREATE TABLE ( ... )</emphasis> <acronym>SQL</acronym>
  341. statement can be found in <filename>Zend/Queue/Adapter/Db/mysql.sql</filename>.
  342. </para>
  343. </sect3>
  344. <sect3 id="zend.queue.adapters.notes.memcacheQ">
  345. <title>MemcacheQ</title>
  346. <para>
  347. Memcache can be downloaded from <ulink
  348. url="http://www.danga.com/memcached/">http://www.danga.com/memcached/</ulink>.
  349. </para>
  350. <para>
  351. MemcacheQ can be downloaded from <ulink
  352. url="http://memcachedb.org/memcacheq/">http://memcachedb.org/memcacheq/</ulink>.
  353. </para>
  354. <itemizedlist>
  355. <listitem>
  356. <para>
  357. <methodname>deleteMessage()</methodname> - Messages are deleted upon
  358. reception from the queue. Calling this function would
  359. have no effect. Calling this function will throw an
  360. error.
  361. </para>
  362. </listitem>
  363. <listitem>
  364. <para>
  365. <methodname>count()</methodname> or <methodname>count($adapter)</methodname>
  366. - MemcacheQ does not support a method for counting the number of items in
  367. a queue. Calling this function will throw an error.
  368. </para>
  369. </listitem>
  370. </itemizedlist>
  371. </sect3>
  372. <sect3 id="zend.queue.adapters.notes.platformjq">
  373. <title>Zend Platform Job Queue</title>
  374. <para>
  375. Job Queue is a feature of Zend Platform's Enterprise Solution offering. It is not a
  376. traditional message queue, and instead allows you to queue a script to execute,
  377. along with the parameters you wish to pass to it. You can find out more about Job
  378. Queue <ulink url="http://www.zend.com/en/products/platform/">on the zend.com
  379. website</ulink>.
  380. </para>
  381. <para>
  382. The following is a list of methods where this adapter's behavior diverges from the
  383. standard offerings:
  384. </para>
  385. <itemizedlist>
  386. <listitem>
  387. <para>
  388. <methodname>create()</methodname> - Zend Platform does not have the concept
  389. of discrete queues; instead, it allows administrators to provide scripts for
  390. processing jobs. Since adding new scripts is restricted to the
  391. administration interface, this method simply throws an exception indicating
  392. the action is forbidden.
  393. </para>
  394. </listitem>
  395. <listitem>
  396. <para>
  397. <methodname>isExists()</methodname> - Just like
  398. <methodname>create()</methodname>, since Job Queue does not have a notion of
  399. named queues, this method throws an exception when invoked.
  400. </para>
  401. </listitem>
  402. <listitem>
  403. <para>
  404. <methodname>delete()</methodname> - similar to
  405. <methodname>create()</methodname>, deletion of JQ scripts is not possible
  406. except via the admin interface; this method raises an exception.
  407. </para>
  408. </listitem>
  409. <listitem>
  410. <para>
  411. <methodname>getQueues()</methodname> - Zend Platform does not allow
  412. introspection into the attached job handling scripts via the
  413. <acronym>API</acronym>. This method throws an exception.
  414. </para>
  415. </listitem>
  416. <listitem>
  417. <para>
  418. <methodname>count()</methodname> - returns the total number of jobs
  419. currently active in the Job Queue.
  420. </para>
  421. </listitem>
  422. <listitem>
  423. <para>
  424. <methodname>send()</methodname> - this method is perhaps the one method that
  425. diverges most from other adapters. The <varname>$message</varname> argument
  426. may be one of three possible types, and will operate differently based on
  427. the value passed:
  428. </para>
  429. <itemizedlist>
  430. <listitem>
  431. <para>
  432. <acronym>string</acronym> - the name of a script registered with Job
  433. Queue to invoke. If passed in this way, no arguments are provided to
  434. the script.
  435. </para>
  436. </listitem>
  437. <listitem>
  438. <para>
  439. <acronym>array</acronym> - an array of values with which to
  440. configure a <classname>ZendApi_Job</classname> object. These may
  441. include the following:
  442. </para>
  443. <itemizedlist>
  444. <listitem>
  445. <para>
  446. <varname>script</varname> - the name of the Job Queue script
  447. to invoke. (Required)
  448. </para>
  449. </listitem>
  450. <listitem>
  451. <para>
  452. <varname>priority</varname> - the job priority to use when
  453. registering with the queue.
  454. </para>
  455. </listitem>
  456. <listitem>
  457. <para>
  458. <varname>name</varname> - a short string describing the job.
  459. </para>
  460. </listitem>
  461. <listitem>
  462. <para>
  463. <varname>predecessor</varname> - the ID of a job on which
  464. this one depends, and which must be executed before this one
  465. may begin.
  466. </para>
  467. </listitem>
  468. <listitem>
  469. <para>
  470. <varname>preserved</varname> - whether or not to retain the
  471. job within the Job Queue history. By default, off; pass a
  472. <constant>TRUE</constant> value to retain it.
  473. </para>
  474. </listitem>
  475. <listitem>
  476. <para>
  477. <varname>user_variables</varname> - an associative array of
  478. all variables you wish to have in scope during job execution
  479. (similar to named arguments).
  480. </para>
  481. </listitem>
  482. <listitem>
  483. <para>
  484. <varname>interval</varname> - how often, in seconds, the job
  485. should run. By default, this is set to 0, indicating it
  486. should run once, and once only.
  487. </para>
  488. </listitem>
  489. <listitem>
  490. <para>
  491. <varname>end_time</varname> - an expiry time, past which the
  492. job should not run. If the job was set to run only once,
  493. and <varname>end_time</varname> has passed, then the job
  494. will not be executed. If the job was set to run on an
  495. interval, it will not execute again once
  496. <varname>end_time</varname> has passed.
  497. </para>
  498. </listitem>
  499. <listitem>
  500. <para>
  501. <varname>schedule_time</varname> - a <acronym>UNIX</acronym>
  502. timestamp indicating when to run the job; by default, 0,
  503. indicating the job should run as soon as possible.
  504. </para>
  505. </listitem>
  506. <listitem>
  507. <para>
  508. <varname>application_id</varname> - the application
  509. identifier of the job. By default, this is
  510. <constant>NULL</constant>, indicating that one will be
  511. automatically assigned by the queue, if the queue was
  512. assigned an application ID.
  513. </para>
  514. </listitem>
  515. </itemizedlist>
  516. <para>
  517. As noted, only the <varname>script</varname> argument is required;
  518. all others are simply available to allow passing more fine-grained
  519. detail on how and when to run the job.
  520. </para>
  521. </listitem>
  522. <listitem>
  523. <para>
  524. <classname>ZendApi_Job</classname> - finally, you may simply pass a
  525. <classname>ZendApi_Job</classname> instance, and it will be passed
  526. along to Platform's Job Queue.
  527. </para>
  528. </listitem>
  529. </itemizedlist>
  530. <para>
  531. In all instances, <methodname>send()</methodname> returns a
  532. <classname>Zend_Queue_Message_PlatformJob</classname> object, which provides
  533. access to the <classname>ZendApi_Job</classname> object used to communicate
  534. with Job Queue.
  535. </para>
  536. </listitem>
  537. <listitem>
  538. <para>
  539. <methodname>receive()</methodname> - retrieves a list of active jobs from
  540. Job Queue. Each job in the returned set will be an instance of
  541. <classname>Zend_Queue_Message_PlatformJob</classname>.
  542. </para>
  543. </listitem>
  544. <listitem>
  545. <para>
  546. <methodname>deleteMessage()</methodname> - since this adapter only works
  547. with Job Queue, this method expects the provided <varname>$message</varname>
  548. to be a <classname>Zend_Queue_Message_PlatformJob</classname> instance, and
  549. will throw an exception otherwise.
  550. </para>
  551. </listitem>
  552. </itemizedlist>
  553. </sect3>
  554. <sect3 id="zend.queue.adapters.notes.array">
  555. <title>Array (local)</title>
  556. <para>
  557. The Array queue is a <acronym>PHP</acronym> <methodname>array()</methodname>
  558. in local memory. The <classname>Zend_Queue_Adapter_Array</classname> is good for
  559. unit testing.
  560. </para>
  561. </sect3>
  562. </sect2>
  563. </sect1>