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/src/main/java/org/springframework/kafka/listener/adapter/BatchMessagingMessageListenerAdapter.java
+7-4
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2016-2017 the original author or authors.
2
+
* Copyright 2016-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class BatchMessagingMessageListenerAdapter<K, V> extends MessagingMessage
Copy file name to clipboardExpand all lines: spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java
+6-3
Original file line number
Diff line number
Diff line change
@@ -428,9 +428,12 @@ else if (parameterizedType.getRawType().equals(List.class)
Copy file name to clipboardExpand all lines: spring-kafka/src/main/java/org/springframework/kafka/support/converter/BatchMessagingMessageConverter.java
+6-1
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2016-2017 the original author or authors.
2
+
* Copyright 2016-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -117,6 +117,11 @@ public void setHeaderMapper(KafkaHeaderMapper headerMapper) {
No conversion is performed on the payloads in this case.
866
+
867
+
If the `BatchMessagingMessageConverter` is configured with a `RecordMessageConverter`, you can also add a generic type to the `Message` parameter and the payloads will be converted.
868
+
See <<payload-conversion-with-batch>> for more information.
869
+
866
870
You can also receive a list of `ConsumerRecord<?, ?>` objects but it must be the only parameter (aside from an optional `Acknowledgment` when using manual commits) defined on the method:
867
871
868
872
[source, java]
@@ -1382,6 +1386,8 @@ When a container is paused, it continues to `poll()` the consumer, avoiding a re
1382
1386
[[serdes]]
1383
1387
==== Serialization/Deserialization and Message Conversion
1384
1388
1389
+
===== Overview
1390
+
1385
1391
Apache Kafka provides a high-level API for serializing/deserializing record values as well as their keys.
1386
1392
It is present with the `org.apache.kafka.common.serialization.Serializer<T>` and
1387
1393
`org.apache.kafka.common.serialization.Deserializer<T>` abstractions with some built-in implementations.
@@ -1460,7 +1466,10 @@ With a class-level `@KafkaListener`, the payload type is used to select which `@
1460
1466
1461
1467
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.
1462
1468
1463
-
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.
1469
+
[[payload-conversion-with-batch]]
1470
+
===== Payload Conversion with Batch Listeners
1471
+
1472
+
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.
1464
1473
1465
1474
By default, the type for the conversion is inferred from the listener argument.
1466
1475
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.
Notice that you can still access the batch headers too.
1500
1509
1501
-
Starting with _versions 2.1.1_, the `org.springframework.core.convert.ConversionService` used by the default
1502
-
`o.s.messaging.handler.annotation.support.MessageHandlerMethodFactory` to reslove parameters for the invocation
1510
+
If the batch converter has a record converter that supports it, you can also receive a list of messages where the payloads are converted according to the generic type:
1511
+
1512
+
[source, java]
1513
+
----
1514
+
@KafkaListener(topics = "blc3", groupId = "blc3")
1515
+
public void listen1(List<Message<Foo>> fooMessages) {
1516
+
...
1517
+
}
1518
+
----
1519
+
1520
+
===== ConversionService Customization
1521
+
1522
+
Starting with _version 2.1.1_, the `org.springframework.core.convert.ConversionService` used by the default
1523
+
`o.s.messaging.handler.annotation.support.MessageHandlerMethodFactory` to resolve parameters for the invocation
1503
1524
of a listener method is supplied with all beans implementing any of the following interfaces:
0 commit comments