アダプタ
Zend_Queueは、
インターフェースZend_Queue_Adapter_AdapterInterfaceを実装する
すべての待ち行列をサポートします。
以下のメッセージ待ち行列サービスがサポートされます:
Apache ActiveMQ.
Zend_Dbを経たデータベースによる待ち行列
Memcacheによる
MemcacheQ待ち行列
Zend Platform
のジョブキュー。
内部配列。ユニットテストに役立ちます。
限定事項
メッセージ・トランザクション処理は、サポートされません。
固有のアダプタ - 設定の構成
デフォルトの設定が示される場合は、パラメータは任意です。
デフォルトの設定が指定されない場合は、パラメータが必要です。
Apache ActiveMQ - Zend_Queue_Adapter_Activemq
ここでリストされたオプションは、既知の必須条件です。
すべてのメッセージ発信サーバが、
ユーザー名またはパスワードを必要とするというわけではありません。
$options['name'] = '/temp/queue1';
これは、使い始めたい待ち行列の名前です。(必須)
$options['driverOptions']['host'] = 'host.domain.tld';
$options['driverOptions']['host'] = '127.0.0.1';
ホストをIPアドレスまたはホスト名にセットするかもしれません。
ホストのデフォルトの設定は '127.0.0.1' です。
$options['driverOptions']['port'] = 61613;
ポートのデフォルトの設定は 61613 です。
$options['driverOptions']['username'] = 'username';
一部のメッセージ発信サーバのために選択できます。
メッセージ発信サーバのためのマニュアルを読んでください。
$options['driverOptions']['password'] = 'password';
一部のメッセージ発信サーバのために選択できます。
メッセージ発信サーバのためのマニュアルを読んでください。
$options['driverOptions']['timeout_sec'] = 2;
$options['driverOptions']['timeout_usec'] = 0;
これは、Zend_Queue_Adapter_Activemqがメッセージを返さない前に
ソケットで読み取り活動を待つ時間です。
Db - Zend_Queue_Adapter_Db
ドライバオプションは、多少の必須のオプションのためにチェックされます。
(例えばtype、host、username、
passwordとdbname)
$options['driverOptions']でパラメータとして、
Zend_DB::factory()のために付加パラメータに沿って渡すかもしれません。
ここでは一覧に示されていませんが、
渡すことができる付加的なオプションはportでしょう。
array(
'host' => 'db1.domain.tld',
'username' => 'my_username',
'password' => 'my_password',
'dbname' => 'messaging',
'type' => 'pdo_mysql',
'port' => 3306, // optional parameter.
),
'options' => array(
// 更新のためにZend_Db_Selectを使います。
// 全てのデータベースがこのフィーチャをサポートできるわけではありません。
Zend_Db_Select::FOR_UPDATE => true
)
);
// データベース待ち行列を作成
$queue = Zend_Queue::factory('Db', $options);
]]>
$options['name'] = 'queue1';
これは、使い始めたい待ち行列の名前です。(必須)
$options['driverOptions']['type'] = 'Pdo';
typeは、
Zend_Db::factory()を
使ってもらいたいアダプタです。
これは、Zend_Db::factory()
クラス・メソッド呼び出しの最初のパラメータです。
$options['driverOptions']['host'] = 'host.domain.tld';
$options['driverOptions']['host'] = '127.0.0.1';
ホストをIPアドレスまたはホスト名にセットするかもしれません。
ホストのデフォルトの設定は '127.0.0.1' です。
$options['driverOptions']['username'] = 'username';
$options['driverOptions']['password'] = 'password';
$options['driverOptions']['dbname'] = 'dbname';
必須のテーブルを作成したデータベース名。
下記の注意部分を見てください。
MemcacheQ - Zend_Queue_Adapter_Memcacheq
$options['name'] = 'queue1';
これは、使い始めたい待ち行列の名前です。(必須)
$options['driverOptions']['host'] = 'host.domain.tld';
$options['driverOptions']['host'] = '127.0.0.1;'
ホストをIPアドレスまたはホスト名にセットするかもしれません。
ホストのデフォルトの設定は '127.0.0.1' です。
$options['driverOptions']['port'] = 22201;
ポートのデフォルトの設定は 22201 です。
Zend Platform Job Queue - Zend_Queue_Adapter_PlatformJobQueue
$options['daemonOptions']['host'] = '127.0.0.1:10003';
The hostname and port corresponding to the Zend Platform Job Queue daemon
you will use. (Required)
$options['daemonOptions']['password'] = '1234';
The password required for accessing the Zend Platform Job Queue daemon.
(Required)
配列 - Zend_Queue_Adapter_Array
$options['name'] = 'queue1';
これは、使い始めたい待ち行列の名前です。(必須)
アダプタ固有の注意
下記のアダプタには注意があります:
Apache ActiveMQ
Zend_Queue_Adapter_Activemqのための可視性期間は利用できません。
ApacheのActiveMQが複数のサブスクリプションをサポートするのに対して、
Zend_Queueはそうしません。
それぞれのサブスクリプションのために
新しいZend_Queueオブジェクトを作成しなければなりません。
ActiveMQの待ち行列または項目の名前は下記のうちの一つで始めなくてはいけません:
/queue/
/topic/
/temp-queue/
/temp-topic/
例えば: /queue/testing
下記の関数はサポートされません:
create() - 待ち行列の作成。
この関数を呼ぶと例外を発生します。
delete() - 待ち行列の削除。
この関数を呼ぶと例外を発生します。
getQueues() - 待ち行列の一覧。
この関数を呼ぶと例外を発生します。
Zend_Db
データベースCREATE TABLE ( ... ) SQL
文がZend/Queue/Adapter/Db/queue.sqlにあります。
MemcacheQ
Memcacheはhttp://www.danga.com/memcached/
からダウンロードできます。
MemcacheQはhttp://memcachedb.org/memcacheq/
からダウンロードできます。
deleteMessage() -
メッセージは、待ち行列から受信と同時に削除されます。
この関数を呼んでも効果がありません。
この関数を呼ぶとエラーを発生します。
count()またはcount($adapter)
- MemcacheQは、待ち行列で件数を数えるためのメソッドをサポートしません。
この関数を呼ぶとエラーを発生します。
Zend Platform Job Queue
Job Queue is a feature of Zend Platform's Enterprise Solution offering. It is not a
traditional message queue, and instead allows you to queue a script to execute,
along with the parameters you wish to pass to it. You can find out more about Job
Queue on the zend.com
website.
The following is a list of methods where this adapter's behavior diverges from the
standard offerings:
create() - Zend Platform does not have the concept
of discrete queues; instead, it allows administrators to provide scripts for
processing jobs. Since adding new scripts is restricted to the
administration interface, this method simply throws an exception indicating
the action is forbidden.
isExists() - Just like
create(), since Job Queue does not have a notion of
named queues, this method throws an exception when invoked.
delete() - similar to
create(), deletion of JQ scripts is not possible
except via the admin interface; this method raises an exception.
getQueues() - Zend Platform does not allow
introspection into the attached job handling scripts via the API. This
method throws an exception.
count() - returns the total number of jobs
currently active in the Job Queue.
send() - this method is perhaps the one method that
diverges most from other adapters. The $message argument
may be one of three possible types, and will operate differently based on
the value passed:
string - the name of a script registered with Job
Queue to invoke. If passed in this way, no arguments are provided to
the script.
array - an array of values with which to
configure a ZendApi_Job object. These may
include the following:
script - the name of the Job Queue script
to invoke. (Required)
priority - the job priority to use when
registering with the queue.
name - a short string describing the job.
predecessor - the ID of a job on which
this one depends, and which must be executed before this one
may begin.
preserved - whether or not to retain the
job within the Job Queue history. By default, off; pass a
true value to retain it.
user_variables - an associative array of
all variables you wish to have in scope during job execution
(similar to named arguments).
interval - how often, in seconds, the job
should run. By default, this is set to 0, indicating it
should run once, and once only.
end_time - an expiry time, past which the
job should not run. If the job was set to run only once,
and end_time has passed, then the job
will not be executed. If the job was set to run on an
interval, it will not execute again once
end_time has passed.
schedule_time - a UNIX
timestamp indicating when to run the job; by default, 0,
indicating the job should run as soon as possible.
application_id - the application
identifier of the job. By default, this is null, indicating
that one will be automatically assigned by the queue, if the
queue was assigned an application ID.
As noted, only the script argument is required;
all others are simply available to allow passing more fine-grained
detail on how and when to run the job.
ZendApi_Job - finally, you may simply pass a
ZendApi_Job instance, and it will be passed
along to Platform's Job Queue.
In all instances, send() returns a
Zend_Queue_Message_PlatformJob object, which provides
access to the ZendApi_Job object used to communicate
with Job Queue.
receive() - retrieves a list of active jobs from
Job Queue. Each job in the returned set will be an instance of
Zend_Queue_Message_PlatformJob.
deleteMessage() - since this adapter only works
with Job Queue, this method expects the provided $message
to be a Zend_Queue_Message_PlatformJob instance, and
will throw an exception otherwise.
配列 (内部)
配列待ち行列はローカルメモリ上のPHP array()です。
Zend_Queue_Adapter_Arrayはユニットテスト用に適しています。