Kafka Cannot Configure Topics on Application Startup, but Later Can Communicate

纵饮孤独 提交于 2020-01-16 16:29:09

问题


We have a spring boot application using spring-kafka (2.2.5.RELEASE) that always gets this error when starting up:

Could not configure topics 
org.springframework.kafka.KafkaException: Timed out waiting to get existing 
topics; nested exception is java.util.concurrent.TimeoutException

However, the application continues to startup:

org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] 
INFO  o.s.k.l.KafkaMessageListenerContainer - partitions revoked: []
INFO  o.s.k.l.KafkaMessageListenerContainer - partitions assigned: [my-reply-topic-1]
INFO  o.s.k.l.KafkaMessageListenerContainer - partitions assigned: [my-request-topic-0]
INFO  o.s.b.w.e.tomcat.TomcatWebServer -
Tomcat started on port(s): 8080 (http) with context path ''

At this point, the application interacts with Kafka as expected.

We like to keep our logs clean, so we would like to understand why this Exception is thrown. Also, it is a bit confusing, because when we move to a different environment where the networking has not been established between the application and the kafka broker(s), we get the same error, but the application does not function. Having the same Exception occur when there is truly a problem and when it can be ignored is irksome when trying to troubleshoot connectivity issues.

Is there a way, on application startup, to determine whether connectivity has been established with Kafka rather than just waiting for a timeout message (which may be a red herring anyway)?


回答1:


If the topic(s) exist already, remove any NewTopic beans from the application context and the KafkaAdmin won't try to connect to the broker at all.



来源:https://stackoverflow.com/questions/55953078/kafka-cannot-configure-topics-on-application-startup-but-later-can-communicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!