我已尝试在两个不同的服务器上运行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/
有什么想法吗?提前谢谢。
答案 0 :(得分: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
这在文档中并不太清楚,这似乎意味着“使用”命令会自动使用管道保留命令 - 就像put自动使用该管道一样。
希望这有助于其他豆子新手!
答案 1 :(得分:3)
https://raw.github.com/kr/beanstalkd/master/doc/protocol.txt
本文档更加清晰。
“use”命令适用于生产者。后续的put命令会将作业放入 此命令指定的管。如果没有发出使用命令,则为作业 将被放入名为“默认”的管中。
“watch”命令将命名管添加到当前的监视列表中 连接。预备命令将从中的任何管中取出作业 观察名单。对于每个新连接,监视列表最初由一个组成 管,名为“默认”。
所以在消费者中你不需要叫“使用”,而是叫“看”
答案 2 :(得分:-1)
它旨在阻止预备 - 它正在等待工作。在另一个终端中,将作业放入管中 - 您的保留命令将返回新作业。