即使Kafka侦听器(spring-kafka)未初始化,如何启动spring应用程序 [英] How to start spring application even if Kafka listener (spring-kafka) doesn't initialize

查看:26
本文介绍了即使Kafka侦听器(spring-kafka)未初始化,如何启动spring应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 spring-kafka 的 Kafka 侦听器的应用程序.我面临的问题是,当 Kafka 侦听器未打开时,spring 上下文初始化失败(各种原因,例如 Kafka 服务器未打开或已关闭).如何确保我的应用程序是独立的.

任何人都可以帮忙.

解决方案

在容器工厂上设置 autoStartup(false).

在您的代码中注入(例如 @Autowired)KafkaListenerEndpointRegistrystart()(在 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屋!

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