安装 libevent
[root
@localhost httpsqs]# wget http://httpsqs.googlecode.com/files/libevent-2.0.12-stable.tar.gz
[root
@localhost httpsqs]# tar -zxf libevent-2.0.12-stable.tar.gz
[root
@localhost httpsqs]# cd libevent-2.0.12-stable
[root
@localhost libevent-2.0.12-stable]# ./configure --prefix=/usr/local/libevent-2.0.12-stable/
[root
@localhost libevent-2.0.12-stable]# make
[[email protected] libevent-2.0.12-stable]# make install
[[email protected] libevent-2.0.12-stable]# cd ..
安装 tokyocabinet
[[email protected] httpsqs]# wget http://httpsqs.googlecode.com/files/tokyocabinet-1.4.47.tar.gz
[[email protected] httpsqs]# tar -zxf tokyocabinet-1.4.47.tar.gz
[[email protected] httpsqs]# cd tokyocabinet-1.4.47
#注:在32位Linux操作系统上编译Tokyo cabinet,请使用./configure --enable-off64代替./configure,可以使数据库文件突破2GB的限制。
#./configure --enable-off64 --prefix=/usr/local/tokyocabinet-1.4.47/
[[email protected] tokyocabinet-1.4.47]# ./configure --prefix=/usr/local/tokyocabinet-1.4.47/
[[email protected] tokyocabinet-1.4.47]# make
[[email protected] tokyocabinet-1.4.47]# make install
[[email protected] libevent-2.0.12-stable]# cd ..
安装 httpsqs
[[email protected] httpsqs]# wget http://httpsqs.googlecode.com/files/httpsqs-1.7.tar.gz
[[email protected] httpsqs]# tar -zxf httpsqs-1.7.tar.gz
[[email protected] httpsqs]# cd httpsqs-1.7
[[email protected] httpsqs-1.7]# make
[[email protected] httpsqs-1.7]# make install
[[email protected] httpsqs-1.7]#
httpsqs -h
--------------------------------------------------------------------------------------------------
HTTP Simple Queue Service - httpsqs v1.7 (April 14, 2011)
-l 监听的IP地址,默认值为 0.0.0.0
-p 监听的TCP端口(默认值:1218)
-x 数据库目录,目录不存在会自动创建(例如:/opt/httpsqs/data)
-t HTTP请求的超时时间(默认值:3)
-s 同步内存缓冲区内容到磁盘的间隔秒数(默认值:5)
-c 内存中缓存的最大非叶子节点数(默认值:1024)
-m 数据库内存缓存大小,单位:MB(默认值:100)
-i 保存进程PID到文件中(默认值:/tmp/httpsqs.pid)
-a 访问HTTPSQS的验证密码(例如:mypass123)
-d 以守护进程运行
-h 显示这个帮助
使用
killall httpsqs 批量杀掉 httpsqs 进程.关闭 httpsqs.
不要使用 pkill -9 httpsqs 或 kill -9 PID of httpsqs.否则,内存中尚未保存到磁盘的数据将会丢失
更多介绍查看: http://code.google.com/p/httpsqs
--------------------------------------------------------------------------------------------------
启动:
[[email protected] httpsqs-1.7]# ulimit -SHn 65535
[[email protected] httpsqs-1.7]# httpsqs -d -p 1218 -x /usr/local/httpsqs/
[[email protected] httpsqs-1.7]# netstat -atln | grep 1218
tcp 0 0 0.0.0.0:1218 0.0.0.0:* LISTEN
测试:
入队测试
-----------------------------
在浏览器中访问:
http://yourid:1218/?name=sunyu&opt=put&data=testcontent&auth=mypass123
如果入队列成功,返回:
HTTPSQS_PUT_OK
如果入队列失败,返回:
HTTPSQS_PUT_ERROR
如果队列已满,返回:
HTTPSQS_PUT_END
从HTTPSQS 1.2版本开始,在返回给客户端的HTTP Header头中增加了一行“Pos: xxx”,输出当前队列的读取位置点.
可在 firebug 或 chorm 返回的 response 中查看到:
Cache-Control:no-cache
Connection:keep-alive
Content-Length:14
Content-Type:text/plain
Date:Sat, 14 Dec 2013 14:00:27 GMT
Pos:5
出队测试
-----------------------------
上面的实例是往队列中 put 值.就是把消息传入队列.
下面是出队的测试:
http://yourid:1218/?name=sunyu&opt=get&auth=mypass123
返回的结果就是之前 put 进去的.
队列状态
-----------------------------
http://yourid:1218/?name=sunyu&opt=status&auth=mypass123
HTTP Simple Queue Service v1.7
------------------------------
Queue Name: sunyu
Maximum number of queues: 1000000
Put position of queue (1st lap): 1
Get position of queue (1st lap): 1
Number of unread queue: 0
以 json 格式查看状态:
http://yourid:1218/?name=sunyu&opt=status_json&auth=mypass123
查看指定队列位置点的内容
-----------------------------
http://yourid:1218/?charset=utf-8&sunyu&opt=view&pos=1&auth=mypass123
pos >=1 并且 <= 1000000000
返回指定队列位置点的内容。
重置指定队列
-----------------------------
http://yourid:1218/?name=sunyu&opt=reset&auth=mypass123
如果重置成功,返回:
HTTPSQS_RESET_OK
如果重置失败,返回:
HTTPSQS_RESET_ERROR
更改指定队列的最大队列数量:
-----------------------------
默认的最大队列长度(100万条):1000000
http://yourid:1218/?name=sunyu&opt=maxqueue&num=1000000000&auth=mypass123"
num >=10 并且 <= 1000000000
如果更改最大队列数量成功,则返回:
HTTPSQS_MAXQUEUE_OK
更改的最大队列数量必须大于当前的“队列写入点”。另外,当“队列写入点”小于“队列读取点”时(即PUT位于圆环的第二圈,而GET位于圆环的第一圈时),本操作将被取消,然后返回给客户端以下信息:
HTTPSQS_MAXQUEUE_CANCEL
不停止服务的情况下,修改定时刷新内存缓冲区内容到磁盘的间隔时间:
-----------------------------
从HTTPSQS 1.3版本开始支持此功能。
默认间隔时间:5秒 或 httpsqs -s 参数设置的值。
http://yourid:1218/?name=sunyu&opt=synctime&num=10&auth=mypass123"
num >=1 and <= 1000000000
如果修改间隔时间成功,则返回:
HTTPSQS_SYNCTIME_OK
如果 num 不在 1 ~ 1000000000 之间,本操作将被取消,然后返回给客户端以下信息:
HTTPSQS_SYNCTIME_CANCEL
密码校验失败:
-----------------------------
从HTTPSQS 1.5版本开始支持此功能。
如果密码校验失败(/?auth=xxx),将返回以下信息:
HTTPSQS_AUTH_FAILED
全局错误:
-----------------------------
如果发生全局错误(即指令、参数错误等),将返回以下信息:
HTTPSQS_ERROR