ScenarioProduction Scenarios
Your Spring Boot Kafka consumer stops consuming after processing a malformed message. How do you fix it?
Reference answer
Root cause: @KafkaListener threw an exception, and without proper error handling, the container retried infinitely on the same offset. Fix: 1) Add DefaultErrorHandler with max attempts and DLT: containerFactory.setCommonErrorHandler(new DefaultErrorHandler(new DeadLetterPublishingRecoverer(kafkaTemplate), new FixedBackOff(1000, 3))). 2) Or use @RetryableTopic with DLT. 3) For deserialization failures specifically: configure ErrorHandlingDeserializer. 4) Immediate fix in production: use kafka-consumer-groups.sh --reset-offsets --shift-by 1 to skip the bad message (cautiously). 5) Always add error handling and DLT from the start.
Expected key concepts: DefaultErrorHandler, DeadLetterPublishingRecoverer, FixedBackOff, infinite retry, DLT, ErrorHandlingDeserializer, shift-by, skip bad message, retry, @RetryableTopic, container