NSQ的NDQ lookup wrong result问题的原因和mac下brew安装指定版本的方法

在使用nsq的时候遇到了莫名其妙的问题,即客户端监听channel读取消息时会报错:

```$xslt

2018-08-10 10:20:24,476 localhost-startStop-1 ERROR lookup.NSQLookupDynMapImpl - NDQ lookup wrong result: {"channels":[],"producers":[{"remote_address":"172.22.0.4:39562","host
name":"f2465b41063f","broadcast_address":"f2465b41063f","tcp_port":4150,"http_port":4151,"version":"1.0.0-compat"}]}

```

google不到原因,后来看代码找到这个log,应该是收到消息但是解析有问题,curl线上的nsq,发现返回是

```$xslt
{"status_code":200,"status_txt":"OK","data":{"channels":["xxx"],"producers":[{"remote_address":"xxx:33724","hostname":"xxx","broadcast_address":"xxx","tcp_port":xx,"http_port":4151,"version":"0.3.8"}]}}
```

线上版本是0.3.8, 而本地是1.0,相应消息格式不一样导致解析错误,为了兼容需要安装0.3.8版本

那么需要安装指定版本的话应该怎么做呢? 

1、首先通过 brew info 查看具体信息

```$xslt
yixinf-jdeMacBook-Pro:/ yixinf-j$ brew info nsq
nsq: stable 1.0.0 (bottled), HEAD
Realtime distributed messaging platform
https://nsq.io/
/usr/local/Cellar/nsq/1.0.0_1 (16 files, 74.3MB) *
  Poured from bottle on 2018-08-01 at 14:39:41
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nsq.rb
==> Dependencies
Build: go ✘, gpm ✘
==> Options
--HEAD
   Install HEAD version
==> Caveats
To have launchd start nsq now and restart at login:
  brew services start nsq
Or, if you don't want/need a background service you can just run:
  nsqd -data-path=/usr/local/var/nsq
yixinf-jdeMacBook-Pro:/ yixinf-j$ 
```

2、找到对应的From,并且将工程clone到本地

```$xslt
git clone https://github.com/Homebrew/homebrew-core.git
Cloning into 'homebrew-core'...
remote: Counting objects: 500022, done.
remote: Total 500022 (delta 0), reused 0 (delta 0), pack-reused 500021
Receiving objects: 100% (500022/500022), 186.55 MiB | 653.00 KiB/s, done.
Resolving deltas: 100% (313856/313856), done.
Checking out files: 100% (4838/4838), done.
```

3、找到相应的commit版本,并切换

```$xslt
git log ./Formula/nsq.rb

commit 7c494caa3bb8733e45ca9a536824fcd050ea5ada
Author: ilovezfs <ilovezfs@icloud.com>
Date:   Mon Jun 20 08:50:01 2016 -0700

    nsq 0.3.8
    
    Closes #2161.
    
    Signed-off-by: ilovezfs <ilovezfs@icloud.com>
    
    
git checkout 7c494caa3bb8733e45ca9a536824fcd050ea5ada    

```

4、执行安装命令  brew install ./Formula/nsq.rb

```$xslt
brew install ./Formula/nsq.rb

```

5、启动

```$xslt
nohup nsqlookupd --http-address 10.106.164.222:4161 --tcp-address 0.0.0.0:4160 --broadcast-address 10.106.164.222 &
nohup nsqd --lookupd-tcp-address=10.106.164.222:4160 --broadcast-address 10.106.164.222 --tcp-address 0.0.0.0:4150 &
nohup nsqadmin --lookupd-http-address=10.106.164.222:4161 --http-address 10.106.164.222:4171 &

```

其他软件方法大致相同。

## MAC安装最新版

参照官网 https://nsq.io/overview/quick_start.html

1、安装

直接在终端执行命令即可
```$xslt
$ brew install nsq
```

2、启动

```
$ nsqlookupd

$ nsqd --lookupd-tcp-address=127.0.0.1:4160

$ nsqadmin --lookupd-http-address=127.0.0.1:4161

```

3、验证
```
$ curl -d 'hello world 2' 'http://127.0.0.1:4151/pub?topic=test'
$ curl -d 'hello world 3' 'http://127.0.0.1:4151/pub?topic=test'
$ curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test'

$ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161

```

可以在http://127.0.0.1:4171/中查看具体信息
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值