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

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

问题描述

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

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.

任何人都可以帮忙.

推荐答案

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

KafkaListenerEndpointRegistrystart()注入(例如@Autowired)到您的代码中(尝试/捕获).

Inject (e.g. @Autowired) the KafkaListenerEndpointRegistry and start() it in your code (in a try/catch).

您还可以通过从注册表中获取容器来单独启动/停止容器(使用@KafkaListener id).

You can also start/stop containers individually by getting them from the registry (using the @KafkaListener id).

这篇关于即使Kafka侦听器(spring-kafka)没有初始化,如何启动spring应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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