Search code examples
spring-bootspring-kafkamessage-listener

How to destroy the kafka message listener container rather than stopping it


I am trying to dynamically add/ remove listeners in run time using the KafkaListenerEndpointRegistry. This class provides option to register new listener in run time, but does not have option to destroy/unregister an already running listener. We have a stop API to stop a particular container, but we have to destroy the container with a particular id and want to re-register it with same id but different set of topics. Could anyone please let us know if we have a feasible solution to do it.


Solution

  • The registry has no API to completely remove containers.

    Don't use the endpoint registry to create these containers, just use the container factory yourself (see the code in the registry), and keep track of them; then you can stop() and destroy() them as needed.