You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/annotation-error-handling.adoc
+11-4Lines changed: 11 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -508,7 +508,11 @@ void listen(List<Thing> in, @Header(KafkaHeaders.CONVERSION_FAILURES) List<Conve
508
508
[[batch-listener-deser-errors]]
509
509
=== Deserialization Errors with Batch Listeners
510
510
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:
512
516
513
517
[source, java]
514
518
----
@@ -526,7 +530,7 @@ public ConsumerFactory<String, Order> consumerFactory() {
526
530
}
527
531
----
528
532
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:
530
534
531
535
[source, java]
532
536
----
@@ -535,15 +539,18 @@ public void listen(List<ConsumerRecord<String, Order>> records) {
535
539
for (ConsumerRecord<String, Order> record : records) {
536
540
if (record.value() == null) {
537
541
// Deserialization failed - throw exception to send to DLT
538
-
// The DeadLetterPublishingRecoverer will restore the original byte[] value
539
542
throw new BatchListenerFailedException("Deserialization failed", record);
540
543
}
541
544
process(record.value());
542
545
}
543
546
}
544
547
----
545
548
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)
0 commit comments