web-dev-qa-db-ja.com

IllegalStateException:トピック[XYZ]が存在せず、missingTopicsFatalがtrueである

Spring BootローカルKafkaトピックから読み取ろうとするアプリ。

アプリが起動し始め、2分間一時停止し、次のエラーをスローします。

19-11-10 14:49:24.700  INFO 20476 --- [  restartedMain] o.a.kafka.common.utils.AppInfoParser     : Kafka startTimeMs: 1573390164696
2019-11-10 14:51:24.793  WARN 20476 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is Java.lang.IllegalStateException: Topic(s) [XYZ] is/are not present and missingTopicsFatal is true
2019-11-10 14:51:24.795  INFO 20476 --- [  restartedMain] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'
2019-11-10 14:51:24.796  INFO 20476 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2019-11-10 14:51:24.810  INFO 20476 --- [  restartedMain] o.Apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-11-10 14:51:24.837  INFO 20476 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-11-10 14:51:24.844 ERROR 20476 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is Java.lang.IllegalStateException: Topic(s) [XYZ] is/are not present and missingTopicsFatal is true
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.Java:185) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.Java:53) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.Java:360) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.Java:158) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.Java:122) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.Java:894) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.Java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:553) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]    
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.Java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]  
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:747) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:397) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]  
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:315) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1226) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]    
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1215) [spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]    
    at com.example.main(NyApplication.Java:38) [classes/:na]    
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]  
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:1.8.0_161]    
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:1.8.0_161]    
    at Java.lang.reflect.Method.invoke(Method.Java:498) ~[na:1.8.0_161] 
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.Java:49) [spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]    
Caused by: Java.lang.IllegalStateException: Topic(s) [ZYX] is/are not present and missingTopicsFatal is true    
    at org.springframework.kafka.listener.AbstractMessageListenerContainer.checkTopics(AbstractMessageListenerContainer.Java:366) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]   
    at org.springframework.kafka.listener.ConcurrentMessageListenerContainer.doStart(ConcurrentMessageListenerContainer.Java:136) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]   
    at org.springframework.kafka.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.Java:323) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE] 
    at org.springframework.kafka.config.KafkaListenerEndpointRegistry.startIfNecessary(KafkaListenerEndpointRegistry.Java:309) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE]  
    at org.springframework.kafka.config.KafkaListenerEndpointRegistry.start(KafkaListenerEndpointRegistry.Java:256) ~[spring-kafka-2.3.3.RELEASE.jar:2.3.3.RELEASE] 
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.Java:182) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]  
    ... 19 common frames omitted    `

kafkaは、ローカルコンピューターのDockerで実行されます。

 docker run --detach --name kafka -p 2181:2181 -p 9092:9092 --env ADVERTISED_Host=192.168.1.89 --env ADVERVTISED_PORT=9092 --env AUTO.CREATE.TOPICS.ENABLE spotify/kafka

bashがコンテナーに

docker exec -it 1234567896b5 bash

私はトピックを見ることができます:

$/opt/kafka_2.11-0.10.1.0/bin# ./kafka-topics.sh --list --zookeeper localhost:2181
$XYZ

トピックは次のコマンドで作成されました:

./kafka-topics.sh --zookeeper  localhost:2181 --create --replication-factor 1 --partitions 3 --topic XYZ

そして私はこれをapplication.ymlアプリの(ポート9092でも試した):

spring:
  kafka:
consumer:
  bootstrap-servers: localhost:2181
  group-id: group_id
  auto-offset-reset: earliest
  key-deserializer: org.Apache.kafka.common.serialization.StringDeserializer
  value-deserializer: org.Apache.kafka.common.serialization.StringDeserializer
producer:
  bootstrap-servers: localhost:2181
  key-serializer: org.Apache.kafka.common.serialization.StringSerializer
  value-serializer: org.Apache.kafka.common.serialization.StringSerializer
3
riorio

構成はKafkaサーバーとしてbootstrapではなくZookeeperを使用しています

2181ではなくポート9092を使用する

また、そのSpotifyコンテナは維持されていないので、新しいものを見つけることをお勧めします

1
cricket_007

これは将来誰かを助けるかもしれません。このエラーTopic(s) [yourTopicName] is/are not present and missingTopicsFatal is trueに対処しようとしています。

構成にBeanを追加する必要がある場合があります。私はこのエラーがあり、これが私の解決策でした-NewTopicのBeanを追加します。

@Bean
public NewTopic adviceTopic() {
    return new NewTopic("user", 3, this.replicationFactor);
}

これは質問に対する回答ではないかもしれませんが、私はこれを他の人に役立つように置いておきます。

構成で適切なポート番号を使用しても同じ例外が発生しました(9092)

これがスタックトレースです。

    Java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.Java:132)
....

Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is Java.lang.IllegalStateException: Topic(s) [my-cute-topic] is/are not present and missingTopicsFatal is true

ソリューション

私は私のローカルkafkaでトピックを作成しましたで、うまくいきました。

0
Aryan Venkat