beanstalkd官网:http://kr.github.io/beanstalkd/
client-libraries https://github.com/kr/beanstalkd/wiki/client-libraries
1,安装 beanstalkd
sudo apt-get install beanstalkd
启动:[email protected]:~$ sudo /etc/init.d/beanstalkd start 关停:[email protected]:~$ sudo /etc/init.d/beanstalkd stop
2,安装客户端库
git clone https://github.com/li-chunli/beanstalk-client cd beanstalk-client/
一个例子:
[email protected]:~/beanstalk/beanstalk-client# cat example.c #include "beanstalk.h" #include <stdio.h> #include <assert.h> int main() { BSJ *job; int id, socket = bs_connect("127.0.0.1", 11300); assert(socket != BS_STATUS_FAIL); assert(bs_use(socket, "test") == BS_STATUS_OK); assert(bs_watch(socket, "test") == BS_STATUS_OK); assert(bs_ignore(socket, "default") == BS_STATUS_OK); id = bs_put(socket, 0, 0, 60, "hello Linux ", 11); assert(id > 0); printf("put job id: %d\n", id); assert(bs_reserve_with_timeout(socket, 2, &job) == BS_STATUS_OK); assert(job); printf("reserve job id: %ld size: %lu\n", job->id, job->size); write(fileno(stderr), job->data, job->size); write(fileno(stderr), "\r\n", 2); printf("delete job id: %ld\n", job->id); assert(bs_delete(socket, job->id) == BS_STATUS_OK); bs_free_job(job); bs_disconnect(socket); } [email protected]:~/beanstalk/beanstalk-client#
编译运行,libbeanstalk.so动态库就在当前目录下,自己添一行到/etc/ld.so.conf.d/libc.conf ,更新ldconfig -v
[email protected]:~/beanstalk/beanstalk-client# gcc example.c -L. -lbeanstalk && ./a.out put job id: 1 reserve job id: 1 size: 11 hello Linux delete job id: 1 [email protected]:~/beanstalk/beanstalk-client# gcc example.c -L. -lbeanstalk && ./a.out put job id: 2 reserve job id: 2 size: 11 hello Linux delete job id: 2 [email protected]:~/beanstalk/beanstalk-client#
时间: 2024-10-08 12:38:05