hadoop - Send KafkaProducer from local machine to hortonworks sandbox on virtualbox -


i have simple producer running through eclipse on windows local machine... want message through kafka, able view broker through zookeeper. see how communication works end end... here goes code:

properties props = new properties();     props.put(producerconfig.bootstrap_servers_config,"localhost:9020");     props.put(producerconfig.value_serializer_class_config,stringserializer.class.getname());     props.put(producerconfig.key_serializer_class_config,stringserializer.class.getname());      kafkaproducer<string,string> producer = new kafkaproducer<string,string>(props);      boolean sync = true;     string topic="mytopic";     string key = "mykey";     string value = "myvalue";      producerrecord<string,string> producerrecord = new producerrecord<string,string>(topic, key, value);      if (sync) {         producer.send(producerrecord).get();     } else {         producer.send(producerrecord);     }      producer.close(); 

however after time

exception in thread "main" java.util.concurrent.executionexception: org.apache.kafka.common.errors.timeoutexception: failed update metadata after 60000 ms. @ org.apache.kafka.clients.producer.kafkaproducer$futurefailure.<init>(kafkaproducer.java:437) @ org.apache.kafka.clients.producer.kafkaproducer.send(kafkaproducer.java:352) @ org.apache.kafka.clients.producer.kafkaproducer.send(kafkaproducer.java:248) @ kafkaproducer.testproducer.main(testproducer.java:30)  caused by: org.apache.kafka.common.errors.timeoutexception: failed update metadata after 60000 ms. 

i have hortonworks sandbox setup, kafka running cannot seem connect it. tried port forwarding in virtualbox network configurations still have same issue. there missing?

you correct in opening ports, presumably 9092 , 2181 default if you're trying create/use kafka consumer. kafka advertises "hostname" producers , consumers use, name needs resolve you're connecting. virtualbox/vm host name not since there's no entry on hosting machine tells resolve hostname , go localhost in case , there's nothing helps resolve dns. edit hosts file that's intrusive. long story short, kafka acknowledges might requirement , provides configuration parameter override kafka tells world how broker. config called advertised.host.name , advertised.port. unless you're changing port need set advertised.host.name.

try setting advertised.host.name in kafka's server.properties configuration file localhost. along opening ports should trick.


Comments