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
Resolves#2357
Spring Framework is planning to deprecate `ListenableFuture` in 6.0.
Add methods to the `KafkaOperations` (`KafkaTemplate`) that return
`CompletableFuture` instead; the `ListenableFuture` methods will be
removed in 3.0.
Provide mechanisms to ease the migration; allowing users to use
`CompletableFuture`s in this release, which will significantly reduce
the effort to switch in 3.0.
**2.9 Only; I will issue a separate PR for main**
See the https://docs.spring.io/spring-kafka/api/org/springframework/kafka/core/KafkaTemplate.html[Javadoc] for more detail.
212
212
213
+
IMPORTANT: In version 3.0, the methods that return `ListenableFuture` will be changed to return `CompletableFuture`.
214
+
To facilitate the migration, the 2.9 version has a method `.usingCompletableFuture()` which will provide the same methods with `CompletableFuture` return types.
215
+
216
+
====
217
+
[source, java]
218
+
----
219
+
KafkaOperations2<String, String> template = new KafkaTemplate<>().usingCompletableFuture();
The `sendDefault` API requires that a default topic has been provided to the template.
214
229
215
230
The API takes in a `timestamp` as a parameter and stores this timestamp in the record.
@@ -553,6 +568,9 @@ The result is a `ListenableFuture` that is asynchronously populated with the res
553
568
The result also has a `sendFuture` property, which is the result of calling `KafkaTemplate.send()`.
554
569
You can use this future to determine the result of the send operation.
555
570
571
+
IMPORTANT: In version 3.0, the futures returned by these methods (and their `sendFuture` properties) will be `CompletableFuture` s instead of `ListenableFuture` s.
572
+
To assit in the transition, using this release, you can convert these types to a `CompleteableFuture` by calling `asCompletable()` on the returned `Future`.
573
+
556
574
If the first method is used, or the `replyTimeout` argument is `null`, the template's `defaultReplyTimeout` property is used (5 seconds by default).
557
575
558
576
Starting with version 2.8.8, the template has a new method `waitForAssignment`.
These will use the template's default `replyTimeout`, there are also overloaded versions that can take a timeout in the method call.
793
811
812
+
IMPORTANT: In version 3.0, the futures returned by these methods (and their `sendFuture` properties) will be `CompletableFuture` s instead of `ListenableFuture` s.
813
+
To assit in the transition, using this release, you can convert these types to a `CompleteableFuture` by calling `asCompletable()` on the returned `Future`.
814
+
794
815
Use the first method if the consumer's `Deserializer` or the template's `MessageConverter` can convert the payload without any additional information, either via configuration or type metadata in the reply message.
795
816
796
817
Use the second method if you need to provide type information for the return type, to assist the message converter.
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/whats-new.adoc
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -35,9 +35,18 @@ You can now configure which inbound headers should be mapped.
35
35
Also available in version 2.8.8 or later.
36
36
See <<headers>> for more information.
37
37
38
+
[[x29-template-changes]]
39
+
==== `KafkaTemplate` Changes
40
+
41
+
In 3.0, the futures returned by this class will be `CompletableFuture` s instead of `ListenableFuture` s.
42
+
See <<kafka-template>> for assistance in transitioning when using this release.
43
+
38
44
[[x29-rkt-changes]]
39
45
==== `ReplyingKafkaTemplate` Changes
40
46
41
47
The template now provides a method to wait for assignment on the reply container, to avoid a race when sending a request before the reply container is initialized.
42
48
Also available in version 2.8.8 or later.
43
49
See <<replying-template>>.
50
+
51
+
In 3.0, the futures returned by this class will be `CompletableFuture` s instead of `ListenableFuture` s.
52
+
See <<replying-template>> and <<exchanging-messages>> for assistance in transitioning when using this release.
0 commit comments