Apache Kafka - DNS resolution failed for url in bootstrap.servers (Failed to construct kafka producer)
<p>I have a problem to construct kafka producer with hostname.
Here's what I did.</p>

<p>1) I set the host.name, port config to <em>server.properties</em></p>

<pre><code>listeners=PLAINTEXT://192.168.0.102:9092

port=9092
host.name=server002.sep.com
</code></pre>

<p>2) I add the host ip and alias name to <em>/etc/hosts</em></p>

<pre><code>127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.102 server002.sep.com
</code></pre>

<p>3) set up a firewall using iptables</p>

<pre><code>-A INPUT -p tcp -m tcp --dport 3888 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2888 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 2181 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 9092 -j ACCEPT
</code></pre>

<p>4) I construct the producer with below configuration.
I set the "hostname:port" instead of "ip:port".</p>

<pre><code>  props = new Properties();

**props.put("bootstrap.servers", "server002.sep.com:9092");
  props.put("acks", "0");
  props.put("retries", "0");
</code></pre>

<p>Exception occurred while running the producer.
Here's the error log.
I don't understand why fail to construct kafka producer.
please check it. :)</p>

<pre><code>Exception in thread "main" org.apache.kafka.common.KafkaException: **Failed to construct kafka producer**
at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:321)
at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:181)
at com.lgcns.sep.kafka.producer.MessageSender.createProducer(MessageSender.java:47)
at com.lgcns.sep.kafka.producer.MessageSender.getInstance(MessageSender.java:22)
at com.lgcns.jartest.producerTest.main(producerTest.java:27)

Caused by: org.apache.kafka.common.config.ConfigException: **DNS resolution failed for url in bootstrap.servers**: server002.sep.com:9092
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:49)
at org.apache.kafka.clients.producer.KafkaProducer.&lt;init&gt;(KafkaProducer.java:269)
... 4 more
</code></pre>