码迷,mamicode.com
首页 > 系统相关 > 详细

beanstalkd任务队列 linux平台安装测试

时间:2016-10-16 21:58:46      阅读:572      评论:0      收藏:0      [点我收藏+]

标签:beanstalkd任务队列 linux平台安装测试



beanstalkd官网:http://kr.github.io/beanstalkd/



client-libraries https://github.com/kr/beanstalkd/wiki/client-libraries


1,安装 beanstalkd

sudo apt-get install beanstalkd


启动:chunli@linux:~$ sudo /etc/init.d/beanstalkd start
关停:chunli@linux:~$ sudo /etc/init.d/beanstalkd stop




2,安装客户端库

git clone https://github.com/li-chunli/beanstalk-client
cd beanstalk-client/


一个例子:

root@linux:~/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);
}
root@linux:~/beanstalk/beanstalk-client#


编译运行,libbeanstalk.so动态库就在当前目录下,自己添一行到/etc/ld.so.conf.d/libc.conf ,更新ldconfig -v

root@linux:~/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
root@linux:~/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
root@linux:~/beanstalk/beanstalk-client#







本文出自 “魂斗罗” 博客,谢绝转载!

beanstalkd任务队列 linux平台安装测试

标签:beanstalkd任务队列 linux平台安装测试

原文地址:http://990487026.blog.51cto.com/10133282/1862436

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!