Method annotated with @KafkaListener not called if there are no messages

Viewed 942

I am using spring-kafka and the method annotated with @KafkaListener is not called if the consumer.poll() method does not return any message. Is it possible to enforce the calling of a method even if consumer.poll() returns an empty list of messages using @KafkaListener?

1 Answers

No, but you can set the idleEventInterval on the listener container factory and then consume ListenerContainerIdleEvents; the event is emitted if a poll returns no records have been received during that interval.

Consume the events by implementing ApplicationListener<ListenerContainerIdleEvent> or using an @EventListener method that receives a ListenerContainerIdleEvent.

Related