Search code examples
javaapache-kafkaamazon-ecskafka-consumer-apispring-kafka

How to stop a service or a kafka consumer after it has been idle for a certain period of time?


I have a Kafka consumer running continuously as a service . I've noticed it only runs for a certain period of time during the day. Instead of keeping it continuously running I want to set some kind of polling timeout for the consumer.

If the consumer doesn't consumes anything/idle for 10mins then I want to shut down the service. Is there some kind of polling timeout and signaling mechanism such as this in Kafka that I can use ?


Solution

  • See ListenerContainerIdleEvent and respective container property and its docs: https://docs.spring.io/spring-kafka/docs/current/reference/html/#idleEventInterval