在運行我的製片人上課的時候Eclipse的我得到這個錯誤沒有默認值: org.apache .kafka.common.config.ConfigException:缺少必需的配置「bootstrap.servers」,它沒有默認值org.apache.kafka.common.config.ConfigException:缺少必需的配置「bootstrap.servers」其中有
這裏是我的製作等級:
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();
}
}
}
上任何指針如何修理它?
您拼寫屬性鍵「bootstrap.servers」'。爲了避免將來出現這種錯誤,請改用常量'ProducerConfig.BOOTSTRAP_SERVERS_CONFIG'。 –