title: Kafka consumer "failed to find leader" when fetching topic metadata
body: <p>When I try to use the Kafka producer and consumer (0.9.0) script to push/pull messages from a topic, I get the errors below.</p>
  
  <h1>Producer Error</h1>
  
  <pre><code>[2016-01-13 02:49:40,078] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  </code></pre>
  
  <h1>Consumer Error</h1>
  
  <pre><code>&gt; [2016-01-13 02:47:18,620] WARN
  &gt; [console-consumer-90116_f89a0b380f19-1452653212738-9f857257-leader-finder-thread],
  &gt; Failed to find leader for Set([test,0])
  &gt; (kafka.consumer.ConsumerFetcherManager$LeaderFinderThread)
  &gt; kafka.common.KafkaException: fetching topic metadata for topics
  &gt; [Set(test)] from broker
  &gt; [ArrayBuffer(BrokerEndPoint(0,192.168.99.100,9092))] failed   at
  &gt; kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:73)    at
  &gt; kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:94)    at
  &gt; kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:66)
  &gt;   at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:63)
  &gt; Caused by: java.io.EOFException   at
  &gt; org.apache.kafka.common.network.NetworkReceive.readFromReadableChannel(NetworkReceive.java:83)
  &gt;   at
  &gt; kafka.network.BlockingChannel.readCompletely(BlockingChannel.scala:129)
  &gt;   at kafka.network.BlockingChannel.receive(BlockingChannel.scala:120)
  &gt;   at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:77)
  &gt;   at
  &gt; kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:74)
  &gt;   at kafka.producer.SyncProducer.send(SyncProducer.scala:119)     at
  &gt; kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:59)
  &gt;   ... 3 more
  </code></pre>
  
  <p>Why am I getting the error, and how do I resolve it?</p>
  
  <h1>Configuration</h1>
  
  <p>Running all components in <strong>Docker containers on Mac</strong>. ZooKeeper and Kafka running in separate Docker containers.</p>
  
  <p>Docker Machine (boot2docker) IP Address: <code>192.168.99.100</code>
  ZooKeeper Port: <code>2181</code>
  Kafka Port: <code>9092</code></p>
  
  <p>Kafka configuration file <code>server.properties</code> sets the following:</p>
  
  <pre><code>host.name=localhost
  broker.id=0
  port=9092
  advertised.host.name=192.168.99.100
  advertised.port=9092
  </code></pre>
  
  <h1>Commands</h1>
  
  <p>I run the following commands from within the kafka server Docker container. I've already created a topic with one partition and a replication factor of 1.</p>
  
  <p>Notice the <strong>leader designation is 0</strong> which might be part of the problem.</p>
  
  <pre><code>root@f89a0b380f19:/opt/kafka/dist# ./bin/kafka-topics.sh --zookeeper 192.168.99.100:2181 --topic test --describe
  Topic:test  PartitionCount:1    ReplicationFactor:1 Configs:
      Topic: test Partition: 0    Leader: 0   Replicas: 0 Isr: 0
  </code></pre>
  
  <p>I then do the following to send some messages:</p>
  
  <pre><code>root@f89a0b380f19:/opt/kafka/dist# ./bin/kafka-console-producer.sh --broker-list 192.168.99.100:9092 --topic test
  one message
  two message
  three message
  four message
  [2016-01-13 02:49:40,078] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  [2016-01-13 02:50:40,080] ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  [2016-01-13 02:51:40,081] ERROR Error when sending message to topic test with key: null, value: 13 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  [2016-01-13 02:52:40,083] ERROR Error when sending message to topic test with key: null, value: 12 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
  </code></pre>
  
  <p>This is the command I'm using to attempt to consume messages which yields the consumer error I posted above.</p>
  
  <pre><code>root@f89a0b380f19:/opt/kafka/dist# ./bin/kafka-console-consumer.sh --zookeeper 192.168.99.100:2181 --topic test --from-beginning
  </code></pre>
  
  <p>I've confirmed ports <code>2181</code> and <code>9092</code> are open and accessible from within the Kafka Docker container:</p>
  
  <pre><code>root@f89a0b380f19:/# nc -z 192.168.99.100 2181; echo $?;
  0
  root@f89a0b380f19:/# nc -z 192.168.99.100 9092; echo $?;
  0
  </code></pre>