SpringBoot集成kafka,运行报 Caused by: java.lang.IllegalStateException: Topic(s) [myTopic] is/are not present and missingTopicsFatal is true

sandy 发表于: 2020-02-12   最后更新时间: 2020-02-12 00:28:45   6,967 游览

之前代码测试的好好的,可是换了一套新的kafka环境运行就报错了,请问大佬是什么原因?

Caused by: java.lang.IllegalStateException: Topic(s) [myTopic2] is/are not present and missingTopicsFatal is true
    at org.springframework.kafka.listener.AbstractMessageListenerContainer.checkTopics(AbstractMessageListenerContainer.java:383) ~[spring-kafka-2.4.1.RELEASE.jar:2.4.1.RELEASE]
    at org.springframework.kafka.listener.ConcurrentMessageListenerContainer.doStart(ConcurrentMessageListenerContainer.java:136) ~[spring-kafka-2.4.1.RELEASE.jar:2.4.1.RELEASE]
    at org.springframework.kafka.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:340) ~[spring-kafka-2.4.1.RELEASE.jar:2.4.1.RELEASE]
    at org.springframework.kafka.config.KafkaListenerEndpointRegistry.startIfNecessary(KafkaListenerEndpointRegistry.java:312) ~[spring-kafka-2.4.1.RELEASE.jar:2.4.1.RELEASE]
    at org.springframework.kafka.config.KafkaListenerEndpointRegistry.start(KafkaListenerEndpointRegistry.java:257) ~[spring-kafka-2.4.1.RELEASE.jar:2.4.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.3.RELEASE.jar:5.2.3.RELEASE]
    ... 12 common frames omitted
发表于 2020-02-12

是因为消费方法监听的topic不存在导致的。

你需要在配置文件中将listener的属性missingTopicsFatal设置为false

spring.kafka.listener.missing-topics-fatal: false

或者手动创建topic。

你的答案

查看kafka相关的其他问题或提一个您自己的问题