Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker for mac : LeaderNotAvailable #397

Closed
thiennhan2310 opened this issue Sep 5, 2018 · 6 comments
Closed

Docker for mac : LeaderNotAvailable #397

thiennhan2310 opened this issue Sep 5, 2018 · 6 comments

Comments

@thiennhan2310
Copy link

thiennhan2310 commented Sep 5, 2018

When I try to run my nodejs app on my local(not docker). It told that LeaderNotAvailble.
I use docker for mac and your docker-composer-single-broker.yml as below

docker-composer-single-broker.yml

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    build: .
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: "172.18.2.77"
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

producer.js

    const  kafka = require('kafka-node');

    var Producer = kafka.Producer,
    KeyedMessage = kafka.KeyedMessage,
    client = new kafka.Client(),
    producer = new Producer(client),
    km = new KeyedMessage('key', 'message'),
    payloads = [
        { topic: 'topic1', messages: 'hi', partition: 0 },
        { topic: 'topic2', messages: ['hello', 'world', km] }
    ];
producer.on('ready', function () {
    producer.send(payloads, function (err, data) {
        console.log(data);
        console.error(err);
    });
});

producer.on('error', function (err) {
  console.error(err)
})
@sscaling
Copy link
Collaborator

sscaling commented Sep 5, 2018

Can't really help with the nodejs library usage (however, I can't see where you specify the bootstrap servers/brokers in this config) - I would recommend trying kafkacat as that is known to be working. I'm using 1.3.1.

Also - please make sure you are using the correct IP in KAFKA_ADVERTISED_HOST_NAME. I think this is typically the en0 device on a mac if you run ifconfig from the command line. The one you're using looks similar to an internal docker IP range so just worth checking.

@sscaling
Copy link
Collaborator

closing due to staleness. No update from OP.

@brandonros
Copy link

version: '3'
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: example
      POSTGRES_USER: postgres
      POSTGRES_DB: postgres
    ports:
      - "5432:5432"
  redis:
    image: redis
    ports:
      - "6379:6379"
  zookeeper:
      image: wurstmeister/zookeeper
      ports:
        - "2181:2181"
  kafka:
      image: wurstmeister/kafka
      ports:
        - "9092:9092"
      environment:
        KAFKA_ADVERTISED_HOST_NAME: kafka
        KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock

/etc/hosts

127.0.0.1       kafka
127.0.0.1       zookeeper

Same problem.

@brandonros
Copy link

I think this is typically the en0 device on a mac if you run ifconfig from the command line.

As in... the IP from my router?

en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	ether 28:f0:76:2c:f9:ee 
	inet6 fe80::18fa:aa7a:6a0f:5cb1%en1 prefixlen 64 secured scopeid 0x6 
	inet 192.168.0.39 netmask 0xffffff00 broadcast 192.168.0.255
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect
	status: active

@brandonros
Copy link

$ docker-machine ip
Error: No machine name(s) specified and no "default" machine exists

from

Running kafka-docker on a Mac:
Install the Docker Toolbox and set KAFKA_ADVERTISED_HOST_NAME to the IP that is returned by the docker-machine ip command.

Your github.io page seems to be out of sync/date with your README?

@sscaling
Copy link
Collaborator

I think this is typically the en0 device on a mac if you run ifconfig from the command line.

As in... the IP from my router?

Yes - please see the Connectivity guide

Your github.io page seems to be out of sync/date with your README?

Yes - it has not been updated for a long time. The files were unfortunately manually changed which broke the github site generation, so requires a bit of administrative work to fix. This I don't have access to do, so requires Wurstmeister to update this. I added an additional task to #407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants