Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

spring boot - Kafka: Topic not present in metadata Exception

I use the Spring KafkaTemplate abilities to send message in Kafak-topic.

Configuration is:

@Bean
public KafkaAdmin createKafkaAdmin() {
    Map<String, Object> configs = new HashMap<>();
    configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:2181");
    return new KafkaAdmin(configs);
}

@Bean
public ProducerFactory<String, String> producerFactory() {
    Map<String, Object> configProps = new HashMap<>();
    configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:2181");
    configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
    configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
    return new DefaultKafkaProducerFactory<>(configProps);
}

 @Bean
 public KafkaTemplate<String, String> kafkaTemplate() {
    return new KafkaTemplate<>(producerFactory());
}

Then I try to send message:

@Autowire
private KafkaTemplate<String, String> kafkaTemplate;

ListenableFuture<SendResult<String, String>> future =
                kafkaTemplate.send("waiting_for_ack",key, value);

But I receive the following exception:

TimeoutException: Topic waiting_for_ack not present in metadata after 60000 ms.

Target topic exist, in which was able to make sure, by:

 ./kafka-topics.sh --zookeeper localhost:2181 --list _consumer_offsets
  
   waiting_for_ack

What am I do wrong, I what way to determine the cause of this exception?

question from:https://stackoverflow.com/questions/66053360/kafka-topic-not-present-in-metadata-exception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to specify the broker urls instead of the zookeeper url in the BOOTSTRAP_SERVERS_CONFIG property. You can try checking for it in the

server.properties

available in /config folder under the kafka installation.Usually it would be

bootstrap.servers=localhost:9092


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...