Skip to content

Commit bc07101

Browse files
committed
Clarify manual handling for batch listener deserialization errors
Explicitly document that batch listeners require manual null-checking and throwing `BatchListenerFailedException` for deserialization errors. Clarify exception header behavior in DLT. Signed-off-by: Soby Chacko <[email protected]>
1 parent a2a239f commit bc07101

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/annotation-error-handling.adoc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,11 @@ void listen(List<Thing> in, @Header(KafkaHeaders.CONVERSION_FAILURES) List<Conve
508508
[[batch-listener-deser-errors]]
509509
=== Deserialization Errors with Batch Listeners
510510

511-
Use `ErrorHandlingDeserializer` to handle deserialization failures gracefully:
511+
IMPORTANT: Batch listeners require **manual handling** of deserialization errors.
512+
Unlike record listeners, there is no automatic error handler that detects and routes deserialization failures to the DLT.
513+
You must explicitly check for failed records and throw `BatchListenerFailedException`.
514+
515+
Use `ErrorHandlingDeserializer` to prevent deserialization failures from stopping the entire batch:
512516

513517
[source, java]
514518
----
@@ -526,7 +530,7 @@ public ConsumerFactory<String, Order> consumerFactory() {
526530
}
527531
----
528532

529-
In your listener, check for `null` values which indicate deserialization failures:
533+
In your listener, you must manually check for `null` values which indicate deserialization failures:
530534

531535
[source, java]
532536
----
@@ -535,15 +539,18 @@ public void listen(List<ConsumerRecord<String, Order>> records) {
535539
for (ConsumerRecord<String, Order> record : records) {
536540
if (record.value() == null) {
537541
// Deserialization failed - throw exception to send to DLT
538-
// The DeadLetterPublishingRecoverer will restore the original byte[] value
539542
throw new BatchListenerFailedException("Deserialization failed", record);
540543
}
541544
process(record.value());
542545
}
543546
}
544547
----
545548

546-
When `DeadLetterPublishingRecoverer` publishes deserialization failures to the DLT, it automatically restores the original `byte[]` value that failed to deserialize.
549+
When `DeadLetterPublishingRecoverer` publishes a deserialization failure to the DLT:
550+
551+
* The original `byte[]` data that failed to deserialize is restored as the record value
552+
* Exception information (class name, message, stacktrace) is added to standard DLT exception headers
553+
* The original `ErrorHandlingDeserializer` exception header is removed by default (set `setRetainExceptionHeader(true)` on the recoverer to keep it)
547554

548555
[[retrying-batch-eh]]
549556
== Retrying Complete Batches

0 commit comments

Comments
 (0)