之前代码测试的好好的,可是换了一套新的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
是因为消费方法监听的topic不存在导致的。
你需要在配置文件中将listener的属性
missingTopicsFatal
设置为false
spring.kafka.listener.missing-topics-fatal: false
或者手动创建topic。
你的答案