title: kafka override advertised.host.name in client java
body: <p>we have kafka 0.8.2.1 running on a single docker container. This is one of several containers set up to work together with docker compose. The docker compose also exposes the kafka 9092 port to the host machine.</p>
  
  <p>The <code>advertised.host.name</code> of the kafka server is set to <code>kafka</code> and all the other containers can talk to it fine using this name.</p>
  
  <p>The problem is that java test programs cannot send messages to the kafka server from the host machine.</p>
  
  <ul>
  <li>Using <code>kafka.javaapi.producer.Producer</code> errors</li>
  <li>Using <code>org.apache.kafka.clients.producer.KafkaProducer</code> hangs for ages  then errors</li>
  </ul>
  
  <p>In both cases if I add an entry to the <code>/etc/hosts</code> file on the host machine it works fine. But this is not ideal, I would like anyone to be able to run these tests without messing with their <code>hosts</code> file.</p>
  
  <p>So is there a way in a java Kafka producer to override the hostname/ip specified in the metadata. We only have one instance of kafka so there is no issue in getting the "right one".</p>
  
  <p>On the <a href="https://cwiki.apache.org/confluence/display/KAFKA/FAQ#FAQ-Whycan%27tmyconsumers%2Fproducersconnecttothebrokers%3F" rel="nofollow noreferrer">FAQ page</a> it implies this can be done:</p>
  
  <blockquote>
    <p>In another rare case where the binding host/port is different from the
    host/port for client connection, you can set advertised.host.name and
    advertised.port for client connection</p>
  </blockquote>
  
  <p>But there are no details how...</p>
  
  <p>Or failing that a more general solution.
  Is there a way to set a <code>hosts</code> entry in the java runtime environment? Without messing with system <code>/etc/hosts</code> files?</p>
  
  <p>Thanks</p>