I look this:nsq cannot consume message by connecting to nsqlookupd
But he doesn’t apply to me,All sorts of ways have been tried.It could be the environment.
system: VMware CentOS + Docker-compose NSQ
Version: all latest
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"
I tried adding -broadcast-address=127.0.0.1 in NSQD command but it would cause an admins page error.
docker-compose config
services:
nsqadmin:
command: /nsqadmin --lookupd-http-address=nsqlookupd:4161
depends_on:
- nsqlookupd
image: nsqio/nsq
ports:
- 4171:4171/tcp
nsqd:
command: /nsqd --lookupd-tcp-address=nsqlookupd:4160 -broadcast-address=127.0.0.1
depends_on:
- nsqlookupd
image: nsqio/nsq
ports:
- 4150:4150/tcp
- 4151:4151/tcp
nsqlookupd:
command: /nsqlookupd
image: nsqio/nsq
ports:
- 4160:4160/tcp
- 4161:4161/tcp
version: '3.0'
I hope you understand what I mean,After all, my English is poor
Any idea for this?
func Producer() {
producer, err := nsq.NewProducer("192.168.132.128:4150", nsq.NewConfig())
if err != nil {
fmt.Println("NewProducer", err)
panic(err)
}
for i := 0; i < 5; i++ {
if err := producer.Publish("test", []byte(fmt.Sprintf("Hello World "))); err != nil {
fmt.Println("Publish", err)
panic(err)
}
}
}
this code is successful He can add messages to nsqd,but I can’t connecting to nsqd
look this:
2019/07/05 14:19:00 INF 2 [test/testq] querying nsqlookupd http://192.168.132.128:4161/lookup?topic=test
2019/07/05 14:19:00 INF 2 [test/testq] (60366475943f:4150) connecting to nsqd
2019/07/05 14:19:01 ERR 2 [test/testq] (60366475943f:4150) error connecting to nsqd - dial tcp: i/o timeout
and this
{"channels":["testq"],"producers":[{"remote_address":"172.19.0.2:57250","hostname":"60366475943f","broadcast_address":"60366475943f","tcp_port":4150,"http_port":4151,"version":"1.1.0"}]}
I think the problem arises in the lookup connection NSQ But I don’t know how to deal with him.
3
Answers
i think you forgot something. Have you add this into your /etc/hosts
It allow your machine to recognize the local network with nsq network on docker. Hope this can help you. CMIIW.
I tried to add as per below,
So your docker compose should be like below,
It should be working now
It seems to me like a network problem, this may not be the best solution for something different from local env, but this works great for me in testing process: