NSQ如何在windows上安装

本文介绍如何安装配置NSQ消息队列,并通过实例演示如何创建Topic、Channel及发送消息。涵盖NSQ的基本使用流程,包括环境搭建、命令行操作及消息处理。

1、NSQ下载链接

http://nsq.io/deployment/installing.html

Current Stable Release: v0.3.8

nsq-0.3.8.windows-amd64.go1.6.2.tar.gz

该压缩包下载解压


2、环境变量path追加

E:\program\nsq-0.3.8.windows-amd64.go1.6.2\bin

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的运行情况。




评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值