I have a Spring Boot Application without Web Interface(spring-boot-web-starter), only inbound communication with Kafka. Using some external dynamic boolean flags outside of this application I would like to decide should Spring Kafka Listener consume or not from specific topic. This flag can be dynamically changed so using KafkaListenerEndpointRegistry and listening events I am able to change state of Kafka listener from "pause" to "resume" based on this external flag change. The problem is that if during application startup external boolean flag is false, I would like to not start Kafka Listener to do not consume messages, but with autoStartUp = false for single Kafka Listener, Spring Boot Application cannot be running as there are no any active Kafka Listeners and I suppose some kind of shutdown event is invoked. Therefore I am curious, is it possible to force Spring Boot Application to run even if there are not active Kafka Listeners during application startup?
I've tried to search for details in documentation, but unfortunately wasn't able to find something useful.
The JVM terminates because there are no active (non-daemon) threads.
All you need to do is start a thread, for example from a thread pool:
@Bean
TaskExecutor exec() {
return new ThreadPoolTaskExecutor();
}
@Bean
ApplicationRunner runner(TaskExecutor exec) {
return args -> {
exec.execute(() -> {});
};
}