NSQ记录


特性

开始

安装

cd /usr/local/src
wget https://s3.amazonaws.com/bitly-downloads/nsq/nsq-1.2.0.linux-amd64.go1.12.9.tar.gz
tar -zxf nsq-1.2.0.linux-amd64.go1.12.9.tar.gz
mv nsq-1.2.0.linux-amd64.go1.12.9 /usr/local/nsq
## 将/usr/local/nsq/bin加入环境变量

配置文件

cd /usr/local/nsq
mkdir conf
mkdir /data/nsq
cd conf
vim nsqd.cfg

1、nsqd.cfg

tcp_address="172.16.0.182:4150"
http_address="172.16.0.182:4151"
nsqlookupd_tcp_addresses = [
    "172.16.0.182:4160"
]
broadcast_address="172.16.0.182"
data_path="/data/nsq/"
msg_timeout="10m"

2、nsqlookupd.cfg

tcp_address="172.16.0.182:4160"
http_address="172.16.0.182:4161"

启动

nsqlookupd -config=/usr/local/nsq/conf/nsqlookupd.cfg &

nsqd -config=/usr/local/nsq/conf/nsqd.cfg &

nsqadmin -lookupd-http-address=172.16.0.182:4161

源码

config := nsq.NewConfig()
//最大允许向两台NSQD服务器接受消息,默认是1,要特别注意
config.MaxInFlight=2
c1, err1 := nsq.NewConsumer("test", "test-channel1", nsq.NewConfig()) // 新建一个消费者

nsq requeue and backoff