nsq 无法通过连接到 nsqlookupd 来消费消息
nsq cannot consume message by connecting to nsqlookupd
我尝试使用 docker-compose 到 运行 nsq,docker-compose.yml
如下:
version: '3'
services:
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160:4160"
- "4161:4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
depends_on:
- nsqlookupd
ports:
- "4150:4150"
- "4151:4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
ports:
- "4171:4171"
我使用的是nsq客户端go-nsq生产和消费消息,直接连接nsqd可以消费消息,连接nsqlookupd不能消费:
consumer.ConnectToNSQD("127.0.0.1:4150") # success (output the consumed messages)
consumer.ConnectToNSQLookupd("127.0.0.1:4161") # failed
2018/01/31 16:39:12 ERR 1 [test/liu] (967fcc2c88ae:4150) error connecting to nsqd - dial tcp: i/o timeout
我可以连接到 nsqlookup 实例:
➜ test_nsq curl http://127.0.0.1:4161/ping
OK%
➜ test_nsq curl http://127.0.0.1:4161/nodes
{"producers":[{"remote_address":"172.22.0.3:59988","hostname":"967fcc2c88ae","broadcast_address":"967fcc2c88ae","tcp_port":4150,"http_port":4151,"version":"1.0.0-compat","tombstones":[false],"topics":["test"]}]}%
源代码link:
https://gist.github.com/liuzxc/1baf85cff7db8dee8c26b8707fc48799
环境:
OS: Mac EI Capitan 10.11.6
go version: 1.9.2
nsq: 1.0.0-compat(latest)
对此有什么想法吗?
我输出了go-nsq日志,然后找到根本原因,应该为nsqd命令添加-broadcast-address=127.0.0.1
,如果没有,nsqd会将其主机名注册到nsqlookupd,客户端无法解析。
我尝试使用 docker-compose 到 运行 nsq,docker-compose.yml
如下:
version: '3'
services:
nsqlookupd:
image: nsqio/nsq
command: /nsqlookupd
ports:
- "4160:4160"
- "4161:4161"
nsqd:
image: nsqio/nsq
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160
depends_on:
- nsqlookupd
ports:
- "4150:4150"
- "4151:4151"
nsqadmin:
image: nsqio/nsq
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
ports:
- "4171:4171"
我使用的是nsq客户端go-nsq生产和消费消息,直接连接nsqd可以消费消息,连接nsqlookupd不能消费:
consumer.ConnectToNSQD("127.0.0.1:4150") # success (output the consumed messages)
consumer.ConnectToNSQLookupd("127.0.0.1:4161") # failed
2018/01/31 16:39:12 ERR 1 [test/liu] (967fcc2c88ae:4150) error connecting to nsqd - dial tcp: i/o timeout
我可以连接到 nsqlookup 实例:
➜ test_nsq curl http://127.0.0.1:4161/ping
OK%
➜ test_nsq curl http://127.0.0.1:4161/nodes
{"producers":[{"remote_address":"172.22.0.3:59988","hostname":"967fcc2c88ae","broadcast_address":"967fcc2c88ae","tcp_port":4150,"http_port":4151,"version":"1.0.0-compat","tombstones":[false],"topics":["test"]}]}%
源代码link:
https://gist.github.com/liuzxc/1baf85cff7db8dee8c26b8707fc48799
环境:
OS: Mac EI Capitan 10.11.6
go version: 1.9.2
nsq: 1.0.0-compat(latest)
对此有什么想法吗?
我输出了go-nsq日志,然后找到根本原因,应该为nsqd命令添加-broadcast-address=127.0.0.1
,如果没有,nsqd会将其主机名注册到nsqlookupd,客户端无法解析。