Support Questions

Find answers, ask questions, and share your expertise

Send KafkaProducer from local machine to hortonworks sandbox on virtualbox

New Contributor

I have a really simple producer that I am running through IntelliJ on my windows local machine What I want is to get a message through to kafka . I have hortonworks sandbox setup, with kafka running but I cannot seem to connect to it. I tried port forwarding in the virtualbox network configurations but still have the same issue. Is there something that I am missing?

Here is my code

import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.Metric;
import org.apache.kafka.common.MetricName;
import org.apache.kafka.common.PartitionInfo;

public class Tutorial {
 public static void main(String[] args)throws Exception{
     String topicName  ="facebook";
     String key = "100";
     String value = "Kafka Message 100";
     Properties props = new Properties();
     props.put("bootstrap.servers", "127.0.0.1:6667");
     props.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
     props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

     Producer<String,String>  producer = new KafkaProducer<String, String>(props);
     ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value);

     try{
         RecordMetadata metadata = producer.send(record).get();
         System.out.println("Message is sent to Partition no " + metadata.partition() + " and offset " + metadata.offset());
         System.out.println("SynchronousProducer Completed with success.");
     }catch

             (Exception e) {
         e.printStackTrace();
         System.out.println("SynchronousProducer failed with an exception");
     }finally{
         producer.close();
     }

 }


}

However after some time I get

java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
SynchronousProducer failed with an exception
	at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:730)
	at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:483)
	at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:430)
	at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:353)
	at Tutorial.main(Tutorial.java:27)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.


Process finished with exit code 0


4 REPLIES 4

Mentor

Confirm your port forwarding includes Kafka broker and zookeeper ports..

Mentor

New Contributor

I have configured the port as per the tutorial but it still not working. Thanks Artem for the suggestion

New Contributor

Yes it does for both kafka-broker and zookeeker. please see image

Thanks

12120-kakfa-port.png

12119-port.png

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.