nsq无法通过连接到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"]}]}%

源代码链接:

https://gist.github.com/liuzxc/1baf85cff7db8dee8c26b8707fc48799

环境:

OS: Mac EI Capitan 10.11.6
go version: 1.9.2
nsq: 1.0.0-compat(latest)

有什么建议吗?

I output the go-nsq log, then find the root cause, should add -broadcast-address=127.0.0.1 for nsqd command, if not,nsqd will register its hostname to nsqlookupd, it cannot be resolved by client.