title: Topic can't be found when producing messages: UNKNOWN_TOPIC_OR_PARTITION
body: <p>I have a two-nodes Kafka cluster (EC2 instances) where each node is used as a separate broker. When I run a producer on the leader instance with the following command:</p>
  
  <pre><code>kafka-console-producer.sh   --broker-list localhost:9092 --topic test
  </code></pre>
  
  <p>I get the following errors.</p>
  
  <blockquote>
    <p>test message
    [2017-01-09 13:22:39,483] WARN Error while fetching metadata with correlation id 0 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
    [2017-01-09 13:22:39,562] WARN Error while fetching metadata with correlation id 1 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
    [2017-01-09 13:22:39,663] WARN Error while fetching metadata with correlation id 2 : {test=UNKNOWN_TOPIC_OR_PARTITION} (org.apache.kafka.clients.NetworkClient)
    ...</p>
  </blockquote>
  
  <p>Listing the topics with <code>kafka-topics.sh</code> shows that the topic exists.</p>
  
  <p>The description of the topic with:</p>
  
  <pre><code>kafka-topics.sh --zookeeper localhost:2181 --describe --topic test
  </code></pre>
  
  <p>returns</p>
  
  <pre><code> Topic:test PartitionCount:8    ReplicationFactor:1 Configs:
       Topic: test    Partition: 0    Leader: 1   Replicas: 1 Isr: 1
       Topic: test    Partition: 1    Leader: 2   Replicas: 2 Isr: 2
       Topic: test    Partition: 2    Leader: 1   Replicas: 1 Isr: 1
       Topic: test    Partition: 3    Leader: 2   Replicas: 2 Isr: 2
       Topic: test    Partition: 4    Leader: 1   Replicas: 1 Isr: 1
       Topic: test    Partition: 5    Leader: 2   Replicas: 2 Isr: 2
       Topic: test    Partition: 6    Leader: 1   Replicas: 1 Isr: 1
       Topic: test    Partition: 7    Leader: 2   Replicas: 2 Isr: 2
  </code></pre>
  
  <p>I am using Kafka 0.10.1.1.</p>
  
  <p><code>server.properties</code> file contains:</p>
  
  <pre><code>listeners=PLAINTEXT://0.0.0.0:9092
  advertised.listeners=PLAINTEXT://0.0.0.0:9092
  port=9092
  host.name=kafka-node1(kafka-node1 for the second host)
  advertised.host.name=kafka-node1(kafka-node2 for the second host)
  advertised.port=9092
  </code></pre>
  
  <p>When I try to produce messages from the second host I get the message below:</p>
  
  <blockquote>
    <p>WARN Got error produce response with correlation id 1 on
    topic-partition test-4, retrying (2 attempts left). Error:
    NOT_LEADER_FOR_PARTITION
    (org.apache.kafka.clients.producer.internals.Sender)
    ....</p>
  </blockquote>
  
  <p>Can anyone please help?</p>