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
Original file line number
Diff line number
Diff line change
@@ -414,6 +414,9 @@ public class KRequestingApplication {
414
414
415
415
Note that we can use Boot's auto-configured container factory to create the reply container.
416
416
417
+
If a non-trivial deserializer is being used for replies, consider using an <<error-handling-deserializer,`ErrorHandlingDeserializer`>> that delegates to your configured deserializer.
418
+
When so configured, the `RequestReplyFuture` will be completed exceptionally and you can catch the `ExecutionException`, with the `DeserializationException` in its `cause` property.
419
+
417
420
The template sets a header (named `KafkaHeaders.CORRELATION_ID` by default), which must be echoed back by the server side.
418
421
419
422
In this case, the following `@KafkaListener` application responds:
@@ -557,6 +560,12 @@ IMPORTANT: The listener container for the replies MUST be configured with `AckMo
557
560
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.
558
561
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.
559
562
563
+
NOTE: If you use an <<error-handling-deserializer,`ErrorHandlingDeserializer`>> with this aggregating template, the framework will not automatically detect `DeserializationException` s.
564
+
Instead, the record (with a `null` value) will be returned intact, with the deserialization exception(s) in headers.
565
+
It is recommended that applications call the utility method `ReplyingKafkaTemplate.checkDeserialization()` method to determine if a deserialization exception occurred.
566
+
See its javadocs for more information.
567
+
568
+
[[receiving-messages]]
560
569
==== Receiving Messages
561
570
562
571
You can receive messages by configuring a `MessageListenerContainer` and providing a message listener or by using the `@KafkaListener` annotation.
@@ -3023,7 +3032,7 @@ CAUTION: When you use a `BatchMessageListener`, you must provide a `failedDeseri
3023
3032
Otherwise, the batch of records are not type safe.
3024
3033
3025
3034
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.
3026
-
Alternatively, you can use consumer configuration properties (which are used by the `ErrorHandlingDeserializer`) to instantiate the delegates.
3035
+
Alternatively, you can use consumer configuration properties (which are used by the `ErrorHandlingDeserializer2`) to instantiate the delegates.
3027
3036
The property names are `ErrorHandlingDeserializer2.KEY_DESERIALIZER_CLASS` and `ErrorHandlingDeserializer2.VALUE_DESERIALIZER_CLASS`.
3028
3037
The property value can be a class or class name.
3029
3038
The following example shows how to set these properties:
0 commit comments