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: src/reference/asciidoc/kafka.adoc
+7-4
Original file line number
Diff line number
Diff line change
@@ -994,7 +994,7 @@ static class MultiListenerBean {
994
994
Starting with _version 2.1.3_, a `@KafkaHandler` method can be designated as the default method which is invoked if there is no match on other methods.
995
995
At most one method can be so designated.
996
996
When using `@KafkaHandler` methods, the payload must have already been converted to the domain object (so the match can be performed).
997
-
Use a custom deserializer, the `JsonDeserializer` or the `StringJsonMessageConverter` with its `TypePrecedence` set to `TYPE_ID` - see <<serdes>> for more information.
997
+
Use a custom deserializer, the `JsonDeserializer` or the `(String|Bytes)JsonMessageConverter` with its `TypePrecedence` set to `TYPE_ID` - see <<serdes>> for more information.
998
998
999
999
[[kafkalistener-lifecycle]]
1000
1000
===== @KafkaListener Lifecycle Management
@@ -1471,7 +1471,7 @@ In addition, the serializer/deserializer can be configured using Kafka propertie
1471
1471
Although the `Serializer`/`Deserializer` API is quite simple and flexible from the low-level Kafka `Consumer` and
1472
1472
`Producer` perspective, you might need more flexibility at the Spring Messaging level, either when using `@KafkaListener` or <<si-kafka,Spring Integration>>.
1473
1473
To easily convert to/from `org.springframework.messaging.Message`, Spring for Apache Kafka provides a `MessageConverter`
1474
-
abstraction with the `MessagingMessageConverter` implementation and its `StringJsonMessageConverter` customization.
1474
+
abstraction with the `MessagingMessageConverter` implementation and its `StringJsonMessageConverter` and `BytesJsonMessageConverter` customization.
1475
1475
The `MessageConverter` can be injected into `KafkaTemplate` instance directly and via
1476
1476
`AbstractKafkaListenerContainerFactory` bean definition for the `@KafkaListener.containerFactory()` property:
1477
1477
@@ -1502,14 +1502,17 @@ With a class-level `@KafkaListener`, the payload type is used to select which `@
1502
1502
====
1503
1503
1504
1504
NOTE: When using the `StringJsonMessageConverter`, you should use a `StringDeserializer` in the kafka consumer configuration and `StringSerializer` in the kafka producer configuration, when using Spring Integration or the `KafkaTemplate.send(Message<?> message)` method.
1505
+
When using the `BytesJsonMessageConverter`, you should use a `BytesDeserializer` in the kafka consumer configuration and `BytesSerializer` in the kafka producer configuration, when using Spring Integration or the `KafkaTemplate.send(Message<?> message)` method.
1506
+
Generally, the `BytesJsonMessageConverter` is more efficient because it avoids a `String` to/from `byte[]` conversion.
1505
1507
1506
1508
[[payload-conversion-with-batch]]
1507
1509
===== Payload Conversion with Batch Listeners
1508
1510
1509
-
Starting with _version 1.3.2_, you can also use a `StringJsonMessageConverter` within a `BatchMessagingMessageConverter` for converting batch messages, when using a batch listener container factory.
1511
+
Starting with _version 1.3.2_, you can also use a `StringJsonMessageConverter` or `BytesJsonMessageConverter` within a `BatchMessagingMessageConverter` for converting batch messages, when using a batch listener container factory.
1512
+
See <<serdes>> for more information.
1510
1513
1511
1514
By default, the type for the conversion is inferred from the listener argument.
1512
-
If you configure the `StringJsonMessageConverter` with a `DefaultJackson2TypeMapper` that has its `TypePrecedence` set to `TYPE_ID` (instead of the default `INFERRED`), then the converter will use type information in headers (if present) instead.
1515
+
If you configure the `(Bytes|String)JsonMessageConverter` with a `DefaultJackson2TypeMapper` that has its `TypePrecedence` set to `TYPE_ID` (instead of the default `INFERRED`), then the converter will use type information in headers (if present) instead.
1513
1516
This allows, for example, listener methods to be declared with interfaces instead of concrete classes.
1514
1517
Also, the type converter supports mapping so the deserialization can be to a different type than the source (as long as the data is compatible).
1515
1518
This is also useful when using <<class-level-kafkalistener,class-level `@KafkaListener` s>> where the payload must have already been converted, to determine which method to invoke.
0 commit comments