I'm trying to start my KafkaListener only when a flag is set to true.
@Component
public class KafkaTopicConsumer {
//Somehow wrap the listener to only start when a property value is set to true
@KafkaListener(topics = "#{@consumerTopic}", groupId = "#{@groupName}")
public void consumeMessage(ConsumerRecord<String, String> message) throws IOException {
logger.info("Consumed message from topic: {} with message: {}", message.topic(), message);
}
Is there a way to only make sure the listener is started when said a property such as start.consumer property is set to true? I don't want the listener starting every time the application is started only when I specify that I want it to be started. Is there a good way to approach this use case?