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-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -989,7 +989,7 @@ static class MultiListenerBean {
989
989
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.
990
990
At most one method can be so designated.
991
991
When using `@KafkaHandler` methods, the payload must have already been converted to the domain object (so the match can be performed).
992
-
Use a custom deserializer, the `JsonDeserializer` or the `StringJsonMessageConverter` with its `TypePrecedence` set to `TYPE_ID` - see <<serdes>> for more information.
992
+
Use a custom deserializer, the `JsonDeserializer` or the `(String|Bytes)JsonMessageConverter` with its `TypePrecedence` set to `TYPE_ID` - see <<serdes>> for more information.
993
993
994
994
[[kafkalistener-lifecycle]]
995
995
===== @KafkaListener Lifecycle Management
@@ -1441,7 +1441,7 @@ In addition, the serializer/deserializer can be configured using Kafka propertie
1441
1441
Although the `Serializer`/`Deserializer` API is quite simple and flexible from the low-level Kafka `Consumer` and
1442
1442
`Producer` perspective, you might need more flexibility at the Spring Messaging level, either when using `@KafkaListener` or <<si-kafka,Spring Integration>>.
1443
1443
To easily convert to/from `org.springframework.messaging.Message`, Spring for Apache Kafka provides a `MessageConverter`
1444
-
abstraction with the `MessagingMessageConverter` implementation and its `StringJsonMessageConverter` customization.
1444
+
abstraction with the `MessagingMessageConverter` implementation and its `StringJsonMessageConverter` and `BytesJsonMessageConverter` customization.
1445
1445
The `MessageConverter` can be injected into `KafkaTemplate` instance directly and via
1446
1446
`AbstractKafkaListenerContainerFactory` bean definition for the `@KafkaListener.containerFactory()` property:
1447
1447
@@ -1472,14 +1472,17 @@ With a class-level `@KafkaListener`, the payload type is used to select which `@
1472
1472
====
1473
1473
1474
1474
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.
1475
+
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.
1476
+
Generally, the `BytesJsonMessageConverter` is more efficient because it avoids a `String` to/from `byte[]` conversion.
1475
1477
1476
1478
[[payload-conversion-with-batch]]
1477
1479
===== Payload Conversion with Batch Listeners
1478
1480
1479
-
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.
1481
+
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.
1482
+
See <<serdes>> for more information.
1480
1483
1481
1484
By default, the type for the conversion is inferred from the listener argument.
1482
-
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.
1485
+
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.
1483
1486
This allows, for example, listener methods to be declared with interfaces instead of concrete classes.
1484
1487
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).
1485
1488
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