消息队列之HTTPSQS

HTTPSQS是什么?

一款基于 HTTP GET/POST 协议的轻量级开源简单消息队列服务,
使用 Tokyo Cabinet 的 B+Tree Key/Value 数据库来做数据的持久化存储。如需了解更多直接参考张宴博客.

安装

此次安装是在centos6.4系统上操作的
安装可以直接参考张宴博客
下面是我安装过程出现的一些问题:

安装gcc编译器即可

1
yum install gcc 

若出现configure: error: zlib.h is required

1
yum install zlib-devel

最后启动

1
httpsqs -d -p 1218 -x /data0/queue

请使用命令“killall httpsqs”、“pkill httpsqs”和“kill cat/tmp/httpsqs.pid”来停止httpsqs。

测试下入队列
http://127.0.0.1:1218/?name=my_queue&opt=put&data=经过URL编码的文本消息&auth=mypass123

接下来使用java客户端操作下(需下载httpsqs4j.jar):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package httpsqs;
import com.daguu.lib.httpsqs4j.Httpsqs4j;
import com.daguu.lib.httpsqs4j.HttpsqsClient;
import com.daguu.lib.httpsqs4j.HttpsqsStatus;
public class Test {
public static void main(String[] args) {
try {
Httpsqs4j.setConnectionInfo("192.168.1.11", 1218, "UTF-8");
HttpsqsClient client = Httpsqs4j.createNewClient();
HttpsqsStatus status = client.getStatus("my_queue");
System.out.println(status.version);
System.out.println(status.queueName);
System.out.println(status.maxNumber);
System.out.println(status.getLap);
System.out.println(status.getPosition);
System.out.println(status.putLap);
System.out.println(status.putPosition);
System.out.println(status.unreadNumber);
//client.putString("test", "test");
System.out.println(client.getString("my_queue"));
} catch (Exception e) {
e.printStackTrace();
}
}
}

运行结果:

1
2
3
4
5
6
7
8
9
1.7
my_queue
1000000
1
1
1
0
1
test

总结

VMware使用桥接方式
/etc/init.d/iptables stop关闭防火墙

参考

参考: