Kafka: A dead letter topic stops one bad record blocking a partition

Without it, a record that always fails is retried for ever and nothing behind it is ever processed.

Code
@Bean
DefaultErrorHandler errorHandler(KafkaTemplate<Object, Object> template) {
    var recoverer = new DeadLetterPublishingRecoverer(template);
    return new DefaultErrorHandler(recoverer, new FixedBackOff(1000L, 3));
}
Output
3 retries 1s apart, then the record is published to orders.DLT
and the consumer moves on to the next offset.
Advertisement
More in KAFKA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11

© Java Coding Hub · About · Contact · Privacy · Terms