Search code examples
spring-kafka

spring-kafka listener shutdown


I'm trying to verify that kafka-listeners are closed gracefully when i shutdown my application (either gracefully or in some aggressive way). Can somebody point me to place where it is handled? I was looking at destroy and close methods but I couldn't locate where kafka client deregistration is actually happening.

What happens if deregistration takes too much time? Or if some other spring bean shutdown hook takes too much time?

Also what it actually means for currently processing events? Can they commit offset during shutdown if they happen to finish their work?

I'm working with spring-kafka 1.3.5 version.


Solution

  • The current 1.3.x version is 1.3.8; you should upgrade. 1.3.9 will be released early January.

    When you stop() a listener container, the container will stop in an orderly fashion and process any records that have previously returned by a pol() (but no further polls will be made). However, you should ensure your listener will process any remaining records within the shutdownTimeout (default 10 seconds, but configurable). The stop() operation will block for that time, waiting for the container(s) to stop.

    With more modern versions (2.2.x, currently 2.2.2) you can use an ApplicationListener or @EventListener to consume ContainerStoppedEvent.