即使Kafka侦听器(spring-kafka)未初始化,如何启动spring应用程序 [英] How to start spring application even if Kafka listener (spring-kafka) doesn't initialize
问题描述
我正在开发一个使用 spring-kafka 的 Kafka 侦听器的应用程序.我面临的问题是,当 Kafka 侦听器未打开时,spring 上下文初始化失败(各种原因,例如 Kafka 服务器未打开或已关闭).如何确保我的应用程序是独立的.
任何人都可以帮忙.
在容器工厂上设置 autoStartup(false)
.
在您的代码中注入(例如 @Autowired
)KafkaListenerEndpointRegistry
和 start()
(在 try/catch 中).>
您还可以通过从注册表中获取容器来单独启动/停止容器(使用 @KafkaListener
id
).
I'm working on an application that uses a Kafka listener using spring-kafka. The problem I'm facing is that the spring context initialization fails when the Kafka listener doesn't turn on (Various reasons, such as Kafka server is not turned on or is down). How can I make sure that my application is independent.
Can anyone please help.
Set autoStartup(false)
on the container factory.
Inject (e.g. @Autowired
) the KafkaListenerEndpointRegistry
and start()
it in your code (in a try/catch).
You can also start/stop containers individually by getting them from the registry (using the @KafkaListener
id
).
这篇关于即使Kafka侦听器(spring-kafka)未初始化,如何启动spring应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!