How to start spring application even if Kafka listener (spring-kafka) doesn't initialize

。_饼干妹妹 提交于 2019-12-01 06:54:11

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/46136582/how-to-start-spring-application-even-if-kafka-listener-spring-kafka-doesnt-in

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