Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 966
daemon54 Avatar asked Dec 24 '22 14:12

daemon54


1 Answers

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

like image 122
Gary Russell Avatar answered May 08 '23 03:05

Gary Russell