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
Handle `DeserializationException` via `ErrorHandlingDeserializer` in
`ReplyingKafkaTemplate`.
**I will do the backports after review/merge; I expect conflicts**
Copy file name to clipboardExpand all lines: src/reference/asciidoc/kafka.adoc
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -411,6 +411,9 @@ public class KRequestingApplication {
411
411
412
412
Note that we can use Boot's auto-configured container factory to create the reply container.
413
413
414
+
If a non-trivial deserializer is being used for replies, consider using an <<error-handling-deserializer,`ErrorHandlingDeserializer`>> that delegates to your configured deserializer.
415
+
When so configured, the `RequestReplyFuture` will be completed exceptionally and you can catch the `ExecutionException`, with the `DeserializationException` in its `cause` property.
416
+
414
417
The template sets a header (named `KafkaHeaders.CORRELATION_ID` by default), which must be echoed back by the server side.
415
418
416
419
In this case, the following `@KafkaListener` application responds:
@@ -554,6 +557,12 @@ IMPORTANT: The listener container for the replies MUST be configured with `AckMo
554
557
To avoid any possibility of losing messages, the template only commits offsets when there are zero requests outstanding, i.e. when the last outstanding request is released by the release strategy.
555
558
After a rebalance, it is possible for duplicate reply deliveries; these will be ignored for any in-flight requests; you may see error log messages when duplicate replies are received for already released replies.
556
559
560
+
NOTE: If you use an <<error-handling-deserializer,`ErrorHandlingDeserializer`>> with this aggregating template, the framework will not automatically detect `DeserializationException` s.
561
+
Instead, the record (with a `null` value) will be returned intact, with the deserialization exception(s) in headers.
562
+
It is recommended that applications call the utility method `ReplyingKafkaTemplate.checkDeserialization()` method to determine if a deserialization exception occurred.
563
+
See its javadocs for more information.
564
+
565
+
[[receiving-messages]]
557
566
==== Receiving Messages
558
567
559
568
You can receive messages by configuring a `MessageListenerContainer` and providing a message listener or by using the `@KafkaListener` annotation.
@@ -3105,7 +3114,7 @@ CAUTION: When you use a `BatchMessageListener`, you must provide a `failedDeseri
3105
3114
Otherwise, the batch of records are not type safe.
3106
3115
3107
3116
You can use the `DefaultKafkaConsumerFactory` constructor that takes key and value `Deserializer` objects and wire in appropriate `ErrorHandlingDeserializer2` instances that you have configured with the proper delegates.
3108
-
Alternatively, you can use consumer configuration properties (which are used by the `ErrorHandlingDeserializer`) to instantiate the delegates.
3117
+
Alternatively, you can use consumer configuration properties (which are used by the `ErrorHandlingDeserializer2`) to instantiate the delegates.
3109
3118
The property names are `ErrorHandlingDeserializer2.KEY_DESERIALIZER_CLASS` and `ErrorHandlingDeserializer2.VALUE_DESERIALIZER_CLASS`.
3110
3119
The property value can be a class or class name.
3111
3120
The following example shows how to set these properties:
0 commit comments