nsq简单安装以及测试

来源:互联网 发布:wifi定位技术算法 编辑:程序博客网 时间:2024/06/09 23:49

介绍

NSQ 是实时的分布式消息处理平台,其设计的目的是用来大规模地处理每天数以十亿计级别的消息。

NSQ 具有分布式和去中心化拓扑结构,该结构具有无单点故障、故障容错、高可用性以及能够保证消息的可靠传递的特征。
二进制下载路径:
https://github.com/nsqio/nsq/releases


下载需要的二进制包:
解压之后:
执行一下命令:

cd /Users/xinzhiyun/nsq/nsq-1.0.0-compat.darwin-amd64.go1.8/bin

安装

在一个 shell 中,运行 nsqlookupd:

➜  bin ./nsqlookupd [nsqlookupd] 2017/11/27 22:48:11.186029 nsqlookupd v1.0.0-compat (built w/go1.8)[nsqlookupd] 2017/11/27 22:48:11.186266 TCP: listening on [::]:4160[nsqlookupd] 2017/11/27 22:48:11.186314 HTTP: listening on [::]:4161

再开启一个 shell,运行 nsqd:

 ➜  bin ./nsqd --lookupd-tcp-address=127.0.0.1:4160[nsqd] 2017/11/27 22:49:11.433686 nsqd v1.0.0-compat (built w/go1.8)[nsqd] 2017/11/27 22:49:11.433755 ID: 280[nsqd] 2017/11/27 22:49:11.433797 NSQ: persisting topic/channel metadata to nsqd.dat[nsqd] 2017/11/27 22:49:11.434504 TCP: listening on [::]:4150[nsqd] 2017/11/27 22:49:11.434596 HTTP: listening on [::]:4151[nsqd] 2017/11/27 22:49:11.434641 LOOKUP(127.0.0.1:4160): adding peer[nsqd] 2017/11/27 22:49:11.434653 LOOKUP connecting to 127.0.0.1:4160[nsqd] 2017/11/27 22:49:11.435319 LOOKUPD(127.0.0.1:4160): peer info {TCPPort:4160 HTTPPort:4161 Version:1.0.0-compat BroadcastAddress:xinzhiyundeMacBook-Pro.local}

再开启第三个 shell,运行 nsqadmin:

➜  bin ./nsqadmin --lookupd-http-address=127.0.0.1:4161[nsqadmin] 2017/11/27 22:50:18.517989 nsqadmin v1.0.0-compat (built w/go1.8)[nsqadmin] 2017/11/27 22:50:18.518233 HTTP: listening on [::]:4171

开启第四个 shell,推送一条初始化数据(并且在集群中创建一个 topic):

 ➜  bin  curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test' OK

最后,开启第五个 shell, 运行 nsq_to_file:

 ➜  bin ./nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:41612017/11/27 22:54:01 INF    1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test2017/11/27 22:54:01 ERR    1 [test/nsq_to_file] error querying nsqlookupd (http://127.0.0.1:4161/lookup?topic=test) - got response 404 Not Found "{\"message\":\"TOPIC_NOT_FOUND\"}"2017/11/27 22:54:31 INFO: opening /tmp/test.xinzhiyundeMacBook-Pro.2017-11-27_22.log2017/11/27 22:55:10 INF    1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test2017/11/27 22:55:10 ERR    1 [test/nsq_to_file] error querying nsqlookupd (http://127.0.0.1:4161/lookup?topic=test) - got response 404 Not Found "{\"message\":\"TOPIC_NOT_FOUND\"}"2017/11/27 22:56:10 INF    1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test2017/11/27 22:56:10 ERR    1 [test/nsq_to_file] error querying nsqlookupd (http://127.0.0.1:4161/lookup?topic=test) - got response 404 Not Found "{\"message\":\"TOPIC_NOT_FOUND\"}"2017/11/27 22:57:10 INF    1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test2017/11/27 22:57:10 INF    1 [test/nsq_to_file] (xinzhiyundeMacBook-Pro.local:4150) connecting to nsqd2017/11/27 22:57:10 ERR    1 [test/nsq_to_file] (xinzhiyundeMacBook-Pro.local:4150) error connecting to nsqd - dial tcp: lookup xinzhiyundeMacBook-Pro.local on 10.39.1.10:53: no such host2017/11/27 22:58:10 INF    1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test2017/11/27 22:58:10 INF    1 [test/nsq_to_file] (xinzhiyundeMacBook-Pro.local:4150) connecting to nsqd2017/11/27 22:58:10 ERR    1 [test/nsq_to_file] (xinzhiyundeMacBook-Pro.local:4150) error connecting to nsqd - dial tcp: lookup xinzhiyundeMacBook-Pro.local on 10.39.1.10:53: no such host

这一步报错 只是报找不到losthost而已,这个不影响测试,解决办法只要在hosts文件添加相关host就可以了

推送更多地数据到 nsqd:

➜  bin  curl -d 'hello world 2' 'http://127.0.0.1:4151/pub?topic=test'OK%                                                                                                                                                           ➜  bin  curl -d 'hello world 3' 'http://127.0.0.1:4151/pub?topic=test'OK%                                                                                                                                                           ➜  bin curl -d curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test01' OK%    

按照预先设想的,在浏览器中打开 http://127.0.0.1:4171/ 就能查看 nsqadmin 的 UI 界面和队列统计数据。同时,还可以在 /tmp 目录下检查 (test.*.log) 文件.

这里写图片描述
这个教程中最重要的是:nsq_to_file (客户端)没有明确地指出 test 主题从哪里产生,它从 nsqlookupd 获取信息,即使在消息推送之后才开始连接 nsqd,消息也并没有消失。

–参考
http://nsq.io

原创粉丝点击