title: Kafka QuickStart, advertised.host.name gives kafka.common.LeaderNotAvailableException
body: <p>I am able to get a simple one-node Kafka (kafka_2.11-0.8.2.1) working locally on one linux machine, but when I try to run a producer remotely I'm getting some confusing errors.</p>
  
  <p>I'm following the quickstart guide at <a href="http://kafka.apache.org/documentation.html#quickstart">http://kafka.apache.org/documentation.html#quickstart</a>.  I stopped the kafka processes and deleted all the zookeeper &amp; karma files in /tmp.  I am on a local 10.0.0.0/24 network NAT-ed with an external IP address, so I modified <code>server.properties</code> to tell zookeeper how to broadcast my external address, as per <a href="https://medium.com/@thedude_rog/running-kafka-in-a-hybrid-cloud-environment-17a8f3cfc284">https://medium.com/@thedude_rog/running-kafka-in-a-hybrid-cloud-environment-17a8f3cfc284</a>:</p>
  
  <pre><code>advertised.host.name=MY.EXTERNAL.IP
  </code></pre>
  
  <p>Then I'm running this:</p>
  
  <pre><code>$ bin/zookeeper-server-start.sh config/zookeeper.properties
  --&gt; ...
  $ export KAFKA_HEAP_OPTS="-Xmx256M -Xms128M" # small test server!
  $ bin/kafka-server-start.sh config/server.properties
  --&gt; ...
  </code></pre>
  
  <p>I opened up the firewall for my producer on the remote machine, and created a new topic and verified it:</p>
  
  <pre><code>$ bin/kafka-topics.sh --create --zookeeper MY.EXTERNAL.IP:2181 --replication-factor 1 --partitions 1 --topic test123
  --&gt; Created topic "test123".
  $ bin/kafka-topics.sh --list --zookeeper MY.EXTERNAL.IP:2181
  --&gt; test123
  </code></pre>
  
  <p>However, the producer I'm running remotely gives me errors:</p>
  
  <pre><code>$ bin/kafka-console-producer.sh --broker-list MY.EXTERNAL.IP:9092 --topic test123
  --&gt; [2015-06-16 14:41:19,757] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
  My Test Message
  --&gt; [2015-06-16 14:42:43,347] WARN Error while fetching metadata [{TopicMetadata for topic test123 -&gt; 
  </code></pre>
  
  <p>No partition metadata for topic test123 due to kafka.common.LeaderNotAvailableException}] for topic [test123]: class kafka.common.LeaderNotAvailableException  (kafka.producer.BrokerPartitionInfo)
      --> (repeated several times)</p>
  
  <p>(I disabled the whole firewall to make sure that wasn't the problem.)</p>
  
  <p>The stdout errors in the karma-startup are repeated: <code>[2015-06-16 20:42:42,768] INFO Closing socket connection to /MY.EXTERNAL.IP. (kafka.network.Processor)</code></p>
  
  <p>And the controller.log gives me this, several times:</p>
  
  <pre><code>java.nio.channels.ClosedChannelException
      at kafka.network.BlockingChannel.send(BlockingChannel.scala:100)
      at kafka.controller.RequestSendThread.liftedTree1$1(ControllerChannelManager.scala:132)
      at kafka.controller.RequestSendThread.doWork(ControllerChannelManager.scala:131)
      at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:60)
  [2015-06-16 20:44:08,128] INFO [Controller-0-to-broker-0-send-thread], Controller 0 connected to id:0,host:MY.EXTERNAL.IP,port:9092 for sending state change requests (kafka.controller.RequestSendThread)
  [2015-06-16 20:44:08,428] WARN [Controller-0-to-broker-0-send-thread], Controller 0 epoch 1 fails to send request Name:LeaderAndIsrRequest;Version:0;Controller:0;ControllerEpoch:1;CorrelationId:7;ClientId:id_0-host_null-port_9092;Leaders:id:0,host:MY.EXTERNAL.IP,port:9092;PartitionState:(test123,0) -&gt; (LeaderAndIsrInfo:(Leader:0,ISR:0,LeaderEpoch:0,ControllerEpoch:1),ReplicationFactor:1),AllReplicas:0) to broker id:0,host:MY.EXTERNAL.IP,port:9092. Reconnecting to broker. (kafka.controller.RequestSendThread)
  </code></pre>
  
  <p>Running this seems to indicate that there is a leader at 0:</p>
  
  <pre><code>$ ./bin/kafka-topics.sh --zookeeper MY.EXTERNAL.IP:2181 --describe --topic test123
  --&gt; Topic:test123   PartitionCount:1    ReplicationFactor:1 Configs:
  Topic: test123  Partition: 0    Leader: 0   Replicas: 0 Isr: 0
  </code></pre>
  
  <p>I reran this test and my server.log indicates that there is a leader at 0:</p>
  
  <pre><code>...
  [2015-06-16 21:58:04,498] INFO 0 successfully elected as leader (kafka.server.ZookeeperLeaderElector)
  [2015-06-16 21:58:04,642] INFO Registered broker 0 at path /brokers/ids/0 with address MY.EXTERNAL.IP:9092. (kafka.utils.ZkUtils$)
  [2015-06-16 21:58:04,670] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
  [2015-06-16 21:58:04,736] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
  </code></pre>
  
  <p>I see this error in the logs when I send a message from the producer:</p>
  
  <pre><code>[2015-06-16 22:18:24,584] ERROR [KafkaApi-0] error when handling request Name: TopicMetadataRequest; Version: 0; CorrelationId: 7; ClientId: console-producer; Topics: test123 (kafka.server.KafkaApis)
  kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
      at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:70)
  </code></pre>
  
  <p>I assume this means that the broker can't be found for some reason?  I'm confused what this means...</p>