1

私は2つの異なるサーバーでbeanstalkdを起動して実行し、いくつかのテストを実行しようとしました(ローカルでソースからコンパイルされたMacOSXで、およびyumでインストールされたCentOSサーバーで)

次のいずれかでサーバーを実行できます

sudo beanstalkd -d -p 11300

また

sudo beanstalkd -p 11300 &

次に、php libを使用してみましたが、フリーズしました。直接接続:

telnet localhost 11300

PHP テスト スクリプトを模倣するために、次のことを行います。

use foo
USING foo
put 0 0 120 5
hello
INSERTED 1
reserve-with-timeout 0
TIMED_OUT

走るだけなら

reserve

無期限に固まっています。

PHPコードは

    /**
    * BeanStalk 0.10 - Example code
    * 
    * This is a quick example to get you started using the client.
    */

    require(dirname(__FILE__).'/../src/BeanStalk.class.php');

    /**
    * Connect to the beanstalkd server(s)
    * 
    * Option array:
    * 
    *       array(
    *           'servers'               => array( 'ip:port'[, 'ip:port'[, ...]] ),
    *           'select'                => 'random wait',
    *           'connection_timeout'    => 0.5,
    *           'peek_usleep'           => 2500,
    *           'connection_retries'    => 3,
    *           'auto_unyaml'           => true
    *       );
    * 
    * select -> this tells the client what type of blocking to use when selecting from 
    * different servers. There are currently four choices:
    * 
    *   random wait:        pick a random server from the list and wait for a job
    * 
    *   sequential wait:    pick the next server in the list and wait for a job
    * 
    *   random peek:        in a loop, pick a random server and peek-ready(), looking for a job
    *                       until a server is found that has something available.
    * 
    *   sequential peek:    in a loop, pick the next server and peek-ready() ... etc.
    * 
    * the *peek modes have a companion setting, peek_usleep, which tells the client how long
    * to usleep() for between peeks to servers.
    * 
    * auto_unyaml -> if true, this causes the client to assume the presence of the syck yaml
    * parser, and attempts to 'unyamlize' yaml output for you before returning it.
    */
echo "opening\n";
    $beanstalk = BeanStalk::open(array(
        'servers'       => array( '127.0.0.1:11300' ),
        'select'        => 'random peek'
    ));

echo "switching tube\n";

    // As in the protocol doc.
    $beanstalk->use_tube('foo');

echo "putting job\n";

    // As in the protocol doc.
    $beanstalk->put(0, 0, 120, 'say hello world');      // Add a job to the queue with highest priority, 
                                                        // no delay, 120 seconds TTR, with the contents
                                                        // 'say hello world'.

                                                        // NOTE: the put() method here supports a final optional 
                                                        // argument, a tube name. If supplied, the server will
                                                        // first switch to that tube, write the job, then switch
                                                        // back to the old tube again.

echo "trying to reserve\n";

    // As in the protocol doc.
    $job = $beanstalk->reserve();                       // Assuming there was nothing in the queue before 
                                                        // we started, this will give us our 'hello world'
                                                        // job back.

echo "about to output\n";    

    // This is a BeanQueueJob object.
    echo $job->get();                                   // Output: 'say hello world'

    Beanstalk::delete($job);                            // Delete the job.

「予約しようとしている」だけでフリーズします。元のコード:

http://sourceforge.net/projects/beanstalk/

何か案は?前もって感謝します。

4

3 に答える 3

7

デフォルト以外のチューブを使用するには、そのチューブの「ウォッチ」を追加する必要があるようです。例えば:

use foo
USING foo
put 0 0 120 5
hello
INSERTED 1
reserve-with-timeout 5
TIMED_OUT
list-tubes
OK 20
---
- default
- foo

watch foo
WATCHING 2
reserve-with-timeout 5
RESERVED 1 5
hello

これはドキュメントではあまり明確ではありません。これは、「use」コマンドが自動的にチューブを使用する予約コマンドを持っていることを暗示しているようです - put がそのチューブを自動的に使用するのと同じです。

これが他のbeanstalkdの初心者に役立つことを願っています!

于 2010-05-12T14:48:14.010 に答える
3

https://raw.github.com/kr/beanstalkd/master/doc/protocol.txt

このドキュメントはより明確です。

「use」コマンドはプロデューサー用です。後続の put コマンドは、このコマンドで指定されたチューブにジョブを配置します。使用コマンドが発行されていない場合、ジョブは「default」という名前のチューブに入れられます。

「watch」コマンドは、指定されたチューブを現在の接続の監視リストに追加します。予約コマンドは、ウォッチ リスト内の任意のチューブからジョブを取得します。新しい接続ごとに、監視リストは最初は「default」という名前の 1 つのチューブで構成されます。

したがって、消費者では「使用」を呼び出す必要はありませんが、「時計」を呼び出す必要があります

于 2013-06-26T07:22:15.320 に答える
-1

予約時にブロックするように設計されています - ジョブを待っています。別のターミナルで、ジョブをチューブに入れます。reserve コマンドが新しいジョブで返されます。

于 2011-02-08T10:33:06.443 に答える