The Kafka version I use is: 0.7.2 
The JDK version is: 1.6.0_20
 
Http://kafka.apache.org/07/quickstart.html The official example is not very complete, the following code is my supplement and can be run after compiling.
 
 
Producer Code
 
 [Java]  View Plain copy import java.util.*;   import kafka.message.message;   Import  kafka.producer.ProducerConfig;   import kafka.javaapi.producer.producer;   Import  kafka.javaapi.producer.ProducerData;      public class producersample {              public static void main (string[)  args)  {           producersample ps =  new producersample ();               Properties props = new properties ();            props.put ("Zk.connect",  "127.0.0.1:2181");            props.put ("Serializer.class",  "Kafka.serializer.StringEncoder");          &Nbsp;    producerconfig config = new producerconfig (props);            producer<string, string> producer =  new Producer<String, String> (config);            producerdata<string, string> data = new producerdata<string,  String> ("Test-topic",  "Test-message2");            producer.send (data);           producer.close ();        }  }  
 
 
 
 
 
Consumer Code 
 
[Java] view plain copy import Java.nio.ByteBuffer;