JavaEar 专注于收集分享传播有价值的技术资料

Apache Kafka - DNS resolution failed for url in bootstrap.servers (Failed to construct kafka producer)

I have a problem to construct kafka producer with hostname. Here's what I did.

1) I set the host.name, port config to server.properties

listeners=PLAINTEXT://192.168.0.102:9092

port=9092
host.name=server002.sep.com

2) I add the host ip and alias name to /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.0.102 server002.sep.com

3) set up a firewall using iptables

-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

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

  props = new Properties();

**props.put("bootstrap.servers", "server002.sep.com:9092");
  props.put("acks", "0");
  props.put("retries", "0");

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

Exception in thread "main" org.apache.kafka.common.KafkaException: **Failed to construct kafka producer**
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:321)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(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.<init>(KafkaProducer.java:269)
... 4 more

1个回答

    最佳答案
  1. i am using 2 vms. 1vm having kafka client java program. 2nd vm having all kafka setups. in server.properties file of vm2 add property "host.name=hostname_of_the_vm2_not_localhost", add this as a bootstrap.server value in kafka client program which is in vm1.

    And you should start vm2 from vm1 terminal only other wise you will get that error. i also got same.