0

我的设置: 所以我刚刚完成了一个 kafka 实例的配置,在 a 上运行VM,地址为:192.168.0.100kafka-consome-consumer.sh我可以使用同一个虚拟机连接到该实例,也可以host使用kafkatool.

在此处输入图像描述

我的问题:我现在正在尝试使用 Java(在 上使用 IntellijIDEA host)向实例生成消息,但应用程序无法连接。我收到以下错误:

Topic ABC not present in metadata after 60000 ms.

这是我的 Kafkaserver.properties地址配置:

############################# Socket Server Settings #############################
listeners=PLAINTEXT://0.0.0.0:9092
advertised.listeners=PLAINTEXT://192.168.0.100:9092

这是我的生产者代码:

        Properties properties = new Properties();
        properties.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.0.100:9092");
        properties.setProperty(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.setProperty(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        properties.put("retries", 0);

        Producer<String, String> producer = new KafkaProducer<String, String>(properties);
        ProducerRecord<String, String> record = new ProducerRecord<String, String>("trucks_GPS", "Hello from a JAVA app");

        producer.send(record, new Callback() {
            public void onCompletion(RecordMetadata recordMetadata, Exception e) {
                if(e != null){
                    System.out.println(e.getMessage());
                }
                else{
                    System.out.println("success");
                }
            }
        });

        producer.flush();
        producer.close();

所要求的准确错误日志 org.apache.kafka.common.errors.TimeoutException: Topic trucks_GPS not present in metadata after 60000 ms.

4

0 回答 0