Kafka无法在应用程序启动时配置主题,但以后可以进行通信 [英] Kafka Cannot Configure Topics on Application Startup, but Later Can Communicate

查看:192
本文介绍了Kafka无法在应用程序启动时配置主题,但以后可以进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用spring-kafka(2.2.5.RELEASE)的spring boot应用程序,在启动时总是会收到此错误:

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 ''

此时,应用程序将按预期与Kafka进行交互.

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

我们希望保持日志整洁,因此我们想了解为什么会引发此异常.而且,这有点令人困惑,因为当我们移至尚未在应用程序和kafka代理之间建立网络的其他环境时,会遇到相同的错误,但应用程序无法运行.尝试解决连接问题时,当确实有问题并且可以忽略时,会发生相同的异常.

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.

在应用程序启动时,有没有一种方法可以确定是否已与Kafka建立连接,而不是仅等待超时消息(无论如何可能是一条鲱鱼)?

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)?

推荐答案

如果主题已经存在,请从应用程序上下文和 KafkaAdmin 中删除所有 NewTopic bean.>完全不会尝试连接到代理.

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.

这篇关于Kafka无法在应用程序启动时配置主题,但以后可以进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆