无法保留工作与beanstalkd

问题描述:

我试图在两个不同的服务器,以获得beanstalkd启动和运行,并做了几个测试(MacOSX上本地从源代码编译,并使用yum安装CentOS的服务器上)无法保留工作与beanstalkd

我可以得到运行的是与

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/

任何想法:从原来的代码?提前致谢。

+0

你可以添加有问题的PHP代码吗?守护进程的另一个版本('beanstalkd -v')。你不必将它作为一个守护进程来运行 - 它会很乐意在终端窗口的前台运行。 – 2010-05-12 12:07:43

+0

版本如果1.4.4,添加了上面的PHP代码。感谢提示不以-d运行,同样的问题适用,但节省时间杀死一个无限循环。 – 2010-05-12 13:31:29

+0

快速注意我可以在不使用新管的情况下进行预留,但list-tubes命令在使用上述telnet命令时确实会列出“foo”。所以可能只是在配置或设置中停止单独的管道工作。 – 2010-05-12 13:59:55

要使用非默认管,它看起来像你需要添加一个“手表”管。例如:

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 

这不是文档,这似乎意味着“使用”上昭然若揭命令自动具有使用管保留命令 - 就像把自动使用该管。

希望这可以帮助其他beanstalkd新手!

+0

你可能想看看[beanstalkc教程](http://github.com/earl/beanstalkc/blob/master/TUTORIAL)(尤指[线138ff](http://github.com/earl/beanstalkc /斑点/主/教程#L138))。尽管本教程是为Python客户端库编写的,但它涵盖了大部分Beanstalkd方面,并且对其他语言/库的用户也很有用。 – earl 2010-05-12 23:18:03

+0

辉煌,感谢链接伯爵 - 易于翻译成其他语言/图书馆作为介绍。使用关键字 – 2010-05-12 23:22:32

+1

是为了将数据放入管中,关键字是检索一个。答案是好的,问题作者写到他没有看到的管道的问题 – asdmin 2010-07-29 15:51:03

它旨在阻止储备 - 它正在等待工作。在另一端,作业放到管 - 您的储备命令将与新的工作回报。

+0

首先,OP使用reserve-with-timeout;这不应该阻止。其次,他们先把工作放在管子上,然后保留这份工作,所以如果其他方面都很好(这个管子上没有其他的观察员),这个工作应该立即可用。 – 2012-08-15 13:42:15

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

这份文件更加清晰。

“使用”命令适用于生产者。随后的put命令会将作业放入由此命令指定的管道的 。如果未发出使用命令,则作业 将被放入名为“default”的管中。

“监视”命令将命名管到观察名单当前 连接。保留命令将采取从工作中的任何 观察名单的管。对于每一个新的连接,观察名单最初由一个 管,命名为“默认”。

所以在消费者中你不需要叫“使用”,而是叫“看”