title: Kafka: Get broker host from ZooKeeper
body: <p>For particular reasons I need to use both - <code>ConsumerGroup</code> (a.k.a. high-level consumer) and <code>SimpleConsumer</code> (a.k.a. low-level consumer) to read from Kafka. For <code>ConsumerGroup</code> I use ZooKeeper-based config and am completely satisfied with it, but <code>SimpleConsumer</code> requires seed brokers to be instantiated. </p>
  
  <p>I don't want to keep list of both - ZooKeeper and broker hosts. Thus, I'm looking for a way to <strong>automatically discover brokers</strong> for a particular topic <strong>from ZooKeeper</strong>. </p>
  
  <p>Because of some indirect information I <em>belief</em> that these data is stored in ZooKeeper under one of the following paths: </p>
  
  <ul>
  <li><code>/brokers/topics/&lt;topic&gt;/partitions/&lt;partition-id&gt;/state</code> </li>
  <li>/brokers/ids/</li>
  </ul>
  
  <p>However, when I try to read data from these nodes, I'm getting serialization error (I'm using <code>com.101tec.zkclient</code> for this): </p>
  
  <blockquote>
    <p>org.I0Itec.zkclient.exception.ZkMarshallingError: java.io.StreamCorruptedException: invalid stream header: 7B226A6D
      at org.I0Itec.zkclient.serialize.SerializableSerializer.deserialize(SerializableSerializer.java:37)
      at org.I0Itec.zkclient.ZkClient.derializable(ZkClient.java:740)
      at org.I0Itec.zkclient.ZkClient.readData(ZkClient.java:773)
      at org.I0Itec.zkclient.ZkClient.readData(ZkClient.java:761)
      at org.I0Itec.zkclient.ZkClient.readData(ZkClient.java:750)
      at org.I0Itec.zkclient.ZkClient.readData(ZkClient.java:744)
      ... 64 elided
    Caused by: java.io.StreamCorruptedException: invalid stream header: 7B226A6D
      at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
      at java.io.ObjectInputStream.(ObjectInputStream.java:299)
      at org.I0Itec.zkclient.serialize.TcclAwareObjectIputStream.(TcclAwareObjectIputStream.java:30)
      at org.I0Itec.zkclient.serialize.SerializableSerializer.deserialize(SerializableSerializer.java:31)
      ... 69 more</p>
  </blockquote>
  
  <p>I can write and read custom Java objects (e.g. Strings) without any problem, so I believe it's not a problem of a client, but rather tricky encoding. Thus, I want to know: </p>
  
  <ol>
  <li>If this is the right way to go, <strong>how to read these nodes properly</strong>?</li>
  <li>If the whole approach is wrong, <strong>what is the right one</strong>?</li>
  </ol>