title: Kafka: client has run out of available brokers
body: <p>UPDATE: It turned out I had an issue with my ports in Docker. Not sure why that fixed this phenomenon.</p>
  
  <p>I believe I have come across a strange error. I am using the <a href="https://github.com/Shopify/sarama" rel="noreferrer">Sarama</a> library and am able to create a consumer successfully. </p>
  
  <pre><code>func main() {
   config = sarama.NewConfig()
   config.ClientID = "go-kafka-consumer"
   config.Consumer.Return.Errors = true
   // Create new consumer
   master, err := sarama.NewConsumer("localhost:9092", config)
   if err != nil {
      panic(err)
   }
  
   defer func() {
       if err := master.Close(); err != nil {
           panic(err)
       }
   }()
  
   partitionConsumer, err := master.ConsumePartition("myTopic",0, 
   sarama.OffsetOldest)
   if err != nil {
       panic(err)
   }
  }
  </code></pre>
  
  <p>As soon as I break this code up and move outside the main routine, I run into the error: </p>
  
  <blockquote>
    <p>kafka: client has run out of available brokers to talk to (Is your cluster reachable?)</p>
  </blockquote>
  
  <p>I have split my code up as follows: the previous main() method I have now converted into a consumer package with a method called NewConsumer() and my new main() calls NewConsumer() like so:</p>
  
  <pre><code>c := consumer.NewConsumer()
  </code></pre>
  
  <p>The panic statement is getting triggered in the line with <code>sarama.NewConsumer</code> and prints out <code>kafka: client has run out of available brokers to talk to (Is your cluster reachable?)</code></p>
  
  <p>Why would breaking up my code this way trigger Sarama to fail to make the consumer? Does Sarama need to be run directly from main?</p>