title: Using Kafka java producer send a message: Producer connection to localhost:9092 unsuccessful
body: <p>I want to send a message to Kafka server. the broker list is not include localhost. But when produce invoke the send method, it's has exception: Producer connection to localhost:9092 unsuccessful</p>
  
  <pre><code>import kafka.javaapi.producer.Producer;
  import kafka.producer.KeyedMessage;
  import kafka.producer.ProducerConfig;
  
  import java.util.Properties;
  
  // create a producer
  
  Properties props = new Properties();
  
  props.put("metadata.broker.list", "192.168.1.203:9092");
  props.put("serializer.class", "kafka.serializer.StringEncoder");
  props.put("request.required.acks", "1");
  
  ProducerConfig config = new ProducerConfig(props);
  
  producer = new Producer&lt;String, String&gt;(config);
  
  //sending...
  String topic = "data_collect_events";
  String message = "_Message_1";
  KeyedMessage&lt;String, String&gt; keyedMessage = new KeyedMessage&lt;String, String&gt;(topic, message);
  producer.send(keyedMessage);
  </code></pre>
  
  <p>exception:</p>
  
  <pre><code>ERROR [main] 2013-07-23 19:27:10,580 kafka.utils.Logging$class: Producer connection to localhost:9092 unsuccessful
  java.net.ConnectException: Connection refused: connect
      at sun.nio.ch.Net.connect0(Native Method)
      at sun.nio.ch.Net.connect(Net.java:364)
      at sun.nio.ch.Net.connect(Net.java:356)
      at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:623)
      at kafka.network.BlockingChannel.connect(BlockingChannel.scala:57)
      at kafka.producer.SyncProducer.connect(SyncProducer.scala:146)
      at kafka.producer.SyncProducer.getOrMakeConnection(SyncProducer.scala:161)
      at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:68)
      at kafka.producer.SyncProducer$$anonfun$send$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(SyncProducer.scala:102)
      at kafka.producer.SyncProducer$$anonfun$send$1$$anonfun$apply$mcV$sp$1.apply(SyncProducer.scala:102)
      at kafka.producer.SyncProducer$$anonfun$send$1$$anonfun$apply$mcV$sp$1.apply(SyncProducer.scala:102)
      at kafka.metrics.KafkaTimer.time(KafkaTimer.scala:33)
      at kafka.producer.SyncProducer$$anonfun$send$1.apply$mcV$sp(SyncProducer.scala:101)
      at kafka.producer.SyncProducer$$anonfun$send$1.apply(SyncProducer.scala:101)
      at kafka.producer.SyncProducer$$anonfun$send$1.apply(SyncProducer.scala:101)
      at kafka.metrics.KafkaTimer.time(KafkaTimer.scala:33)
      at kafka.producer.SyncProducer.send(SyncProducer.scala:100)
      at kafka.producer.async.DefaultEventHandler.kafka$producer$async$DefaultEventHandler$$send(DefaultEventHandler.scala:244)
      at kafka.producer.async.DefaultEventHandler$$anonfun$dispatchSerializedData$1.apply(DefaultEventHandler.scala:107)
      at kafka.producer.async.DefaultEventHandler$$anonfun$dispatchSerializedData$1.apply(DefaultEventHandler.scala:101)
      at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:80)
      at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:80)
      at scala.collection.Iterator$class.foreach(Iterator.scala:631)
      at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:161)
      at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:194)
      at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:39)
      at scala.collection.mutable.HashMap.foreach(HashMap.scala:80)
      at enter code herekafka.producer.async.DefaultEventHandler.dispatchSerializedData(DefaultEventHandler.scala:101)
      at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:73)
      at kafka.producer.Producer.send(Producer.scala:74)
      at kafka.javaapi.producer.Producer.send(Producer.scala:32)
  </code></pre>