Description
In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.1.3
Application: SpringBoot application uses spring-kafka module to consume and process the messages. MessageListenerContainer concurrency is 4. CommonContainerStoppingErrorHandler is chosen to stop the Container on any failures. Assume it would take 60 seconds to complete processing any message.
Scenario: One of the MessageListenerContainer instace throws a fatal exception. CommonContainerStoppingErrorHandler would stop the MessageListenerContainerContainer. At this point, org.springframework.kafka.event.ContainerStoppedEvent is published 5 times (concurrency + maincontainer), eventhough MessageListenerContainer instances are processing messages.
Actually, it would take some time to complete processing of the messages in other MessageListenerContainer instaces.
Problem:
- As of now there is no exact ApplicationListener that is published after the actual spring-kafka component is closed.
- org.springframework.kafka.event.ContainerStoppedEvent is sent for all the MessageListenerContainer instances and the main container. Because of this, from the application side we have to maintain some state to have count of how many events are received. I feel here, publishing one event is sufficient here once the main container is actually stopped. For MessageListenerContainer instances any way org.springframework.kafka.event.ConsumerStoppedEvent is published with the proper reason.
Request: Consider sending a single org.springframework.kafka.event.ContainerStoppedEvent by tracking the closed MessageListenerContainer instances count after it receives notification using 'childStopped' method.
Sample
https://github.com/LokeshAlamuri/SpringBootKafkaConsumerDemo/