skip to Main Content

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'

enter image description here

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


  1. i think you forgot something. Have you add this into your /etc/hosts

    127.0.0.1 nsqd
    

    It allow your machine to recognize the local network with nsq network on docker. Hope this can help you. CMIIW.

    Login or Signup to reply.
  2. I tried to add as per below,

    --broadcast-address=nsqd
    

    So your docker compose should be like below,

    nsqd:
      command: /nsqd --lookupd-tcp-address=nsqlookupd:4160 --broadcast-address=nsqd
      depends_on:
      - nsqlookupd
      image: nsqio/nsq
      ports:
      - 4150:4150/tcp
      - 4151:4151/tcp
    

    It should be working now

    Login or Signup to reply.
  3. 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:

    version: '3'
    services:
      nsqlookupd:
        image: nsqio/nsq
        command: /nsqlookupd
        network_mode: host
    
      nsqd:
        image: nsqio/nsq
        command: /nsqd --lookupd-tcp-address=localhost:4160 # nsqlookupd:4160
        depends_on:
          - nsqlookupd
        network_mode: host
    
      nsqadmin:
        image: nsqio/nsq
        command: /nsqadmin --lookupd-http-address=localhost:4161 # nsqlookupd:4160
        depends_on:
          - nsqlookupd
        network_mode: host
      
      nsqfiles:
        image: nsqio/nsq
        command: /nsq_to_file --lookupd-http-address=localhost:4161 --topic=testing --output-dir=/tmp/nsq/logs
        depends_on:
          - nsqlookupd
        network_mode: host
        volumes:
          - messages-queue:/tmp/nsq/logs
    
    volumes:
      messages-queue:
        driver: local
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search