I'm getting this error when running my producer class in Eclipse: org.apache.kafka.common.config.ConfigException: Missing required configuration "bootstrap.servers" which has no default value
Here is my producer class:
public class SimpleProducer {
public static void main(String[] args) throws Exception {
try {
String topicName = "mytopic";
String key = "key1";
String value = "Value-1";
Properties prop = new Properties();
prop.put("bootstrap.server","localhost:9092");
prop.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
prop.put("value.serializer","org.apache.kafka.cpmmon.serialization.StringSerializer");
Producer<String, String> producer = new KafkaProducer<>(prop);
ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value);
producer.send(record);
producer.close();
System.out.println("SimpleProducer Completed.");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Any pointers on how to fix it?
Just change the
prop.put("bootstrap.server","localhost:9092");
to
prop.put("bootstrap.servers","localhost:9092");
And in your code
prop.put("value.serializer","prop.put("value.serializer","org.apache.kafka.cpmmon.serialization.StringSerializer");
the common
is not correctly,the right package is org.apache.kafka.common.serialization.StringSerializer