2、环境变量path追加
E:programnsq-0.3.8.windows-amd64.go1.6.2bin
3、新建CMD命令行,运行命令:
nsqlookupd
4、再新建一个CMD命令行,运行命令:
nsqd --lookupd-tcp-address=127.0.0.1:4160
5、再新建一个CMD命令行,运行命令:
nsqadmin --lookupd-http-address=127.0.0.1:4161
6、再新建一个CMD命令行(windows上用git bash)发布一个带有初始化信息的topic,运行命令:
curl -d 'hello world 1' 'http://127.0.0.1:4151/put?topic=test'
此时,nsqd命令行中,显示以下信息:
[nsqd] 2016/09/05 10:42:45.369968 TOPIC(test): created
[nsqd] 2016/09/05 10:42:45.370968 NSQ: persisting topic/channel metadata to nsqd.864.dat
[nsqd] 2016/09/05 10:42:45.371968 LOOKUPD(127.0.0.1:4160): topic REGISTER test
nslookupd命令行中,显示以下信息:
[nsqlookupd] 2016/09/05 10:42:33.620296 CLIENT(127.0.0.1:41334): pinged (last ping 14.9998579s)
[nsqlookupd] 2016/09/05 10:42:45.371968 DB: client(127.0.0.1:41334) REGISTER category:topic key:test subkey:
[nsqlookupd] 2016/09/05 10:42:48.620154 CLIENT(127.0.0.1:41334): pinged (last ping 14.999858s)
7、此时topic暂无任何通道channel连接该topic,故发布至topic中的消息将会全部驻留在topic本身内部,我们可以尝试多发几条信息至该topic:
curl -d 'hello world 2' 'http://127.0.0.1:4151/put?topic=test'
curl -d 'hello world 3' 'http://127.0.0.1:4151/put?topic=test'
curl -d 'hello world 4' 'http://127.0.0.1:4151/put?topic=test'
此时,执行完成之后,该名为test的topic,其内部有4条消息待处理,即:
'hello world 1'、'hello world 2'、'hello world 3'、'hello world 4'
8、此时我们新建一个channel,来消费这些消息:
nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
执行命令完,显示以下信息
GY@GY-PC MINGW32 ~
$ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
2016/09/05 12:14:55 INF 1 [test/nsq_to_file] querying nsqlookupd http://127.0.0.1:4161/lookup?topic=test
2016/09/05 12:14:55 INF 1 [test/nsq_to_file] (GY-PC:4150) connecting to nsqd
2016/09/05 12:14:55 INFO: opening C:/Users/GY/AppData/Local/Temp/test.GY-PC.2016-09-05_12.log
2016/09/05 12:14:55 syncing 1 records to disk
2016/09/05 12:15:25 syncing 3 records to disk
2016/09/05 12:16:08 INF 1 [test/nsq_to_file] querying nsqlookupd
http://127.0.0.1:4161/lookup?topic=test
查看log文件

9、http://127.0.0.1:4171/
是nsqadmin生成的控制台查看,根据这个url可以查看Nsq的运行情况。