Search code examples
springapache-kafkaspring-kafka

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.


Solution

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