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", "");
     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);

         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.");

             (Exception e) {
         System.out.println("SynchronousProducer failed with an exception");



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>(
	at org.apache.kafka.clients.producer.KafkaProducer.doSend(
	at org.apache.kafka.clients.producer.KafkaProducer.send(
	at org.apache.kafka.clients.producer.KafkaProducer.send(
	at Tutorial.main(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.intellij.rt.execution.application.AppMain.main(
Caused by: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.

Process finished with exit code 0



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


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




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