Search code examples
spring-kafka

Which moment is preferable to programmatically start a listener/consumer in Spring Kafka?


I have similar code like this answer. But now the question is when to start the listener programmatically, once the spring app starts. Should I write an event listener for an application event or are there more preferable ways?


Solution

  • You can either use an ApplicationListener or implement SmartLifecycle and start the containers in the start() method.