javaapache-kafkaspring-kafka

How to disable a method annotated with @KafkaListener runtime


I have a spring-boot app which utilizes spring-kafka with the @KafkaListener annotation.

I am looking for a way to interact with the consumer such that I can disable the consumer runtime without having to stop the rest of the app, preferably by flipping some boolean flag. Does spring-kafka supply some way to do this?


Solution

  • Use the KafkaListenerEndpointRegistry to find, start, and stop all/any listeners.

    https://docs.spring.io/spring-kafka/reference/kafka/receiving-messages/kafkalistener-lifecycle.html