org.apache.kafka.common.config.ConfigException:缺少必需的配置“bootstrap.servers”,它没有默认值

时间:2017-06-05 17:09:49

标签: apache-kafka kafka-producer-api

Eclipse 中运行我的生产者类时出现此错误: 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();
    }
  }
}

有关如何修复它的任何指示?

3 个答案:

答案 0 :(得分:6)

只需更改

即可

prop.put("bootstrap.servers","localhost:9092");

prop.put("value.serializer","prop.put("value.serializer","org.apache.kafka.cpmmon.serialization.StringSerializer");

并在您的代码中

common

org.apache.kafka.common.serialization.StringSerializer不正确,正确的包是. clonevar newdiag = diag . replace newdiag = "pneumonia" if strpos(strlower(diag),"pneumonia")>0 (3 real changes made) . list, clean noobs diag newdiag pneumonia pneumonia Pneumonia pneumonia Bronchial pneumonia pneumonia Flu and pneumonia pneumonia earache earache

答案 1 :(得分:1)

使用以下内容并避免使用硬编码值

有关

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

使用

prop.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServer);
prop.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
prop.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

ProducerConfig 可在 org.apache.kafka.clients.producer 包中找到

答案 2 :(得分:-1)

在这里发现了两个观察结果

1。

替换

<div wire:ignore id="for-bootstrap-select">
     <select class="form-control" data-container="#for-bootstrap-select">
         @foreach($data as $item)
            <option value="{{ $item->id }}">{{ $item->name }}</option>
         @endforeach
     </select>
</div>

作者

prop.put("bootstrap.server","localhost:9092");

bootstrap.server-不正确

bootstrap.server s -正确

2。

替换

prop.put("bootstrap.servers","localhost:9092");

通过

org.apache.kafka.cpmmon.serialization.StringSerializer