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#2318
Add an option to wait for assignment to the `ReplyingKafkaTemplate`; useful
when using `auto.offset.reset=latest` to avoid sending a request with the reply
sent before the container is initialized.
**cherry-pick to 2.9.x, 2.8.x**
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/asciidoc/kafka.adoc
+8
Original file line number
Diff line number
Diff line change
@@ -555,6 +555,11 @@ You can use this future to determine the result of the send operation.
555
555
556
556
If the first method is used, or the `replyTimeout` argument is `null`, the template's `defaultReplyTimeout` property is used (5 seconds by default).
557
557
558
+
Starting with version 2.8.8, the template has a new method `waitForAssignment`.
559
+
This is useful if the reply container is configured with `auto.offset.reset=latest` to avoid sending a request and a reply sent before the container is initialized.
560
+
561
+
IMPORTANT: When using manual partition assignment (no group management), the duration for the wait must be greater than the container's `pollTimeout` property because the notification will not be sent until after the first poll is completed.
562
+
558
563
The following Spring Boot application shows an example of how to use the feature:
559
564
560
565
====
@@ -570,6 +575,9 @@ public class KRequestingApplication {
570
575
@Bean
571
576
public ApplicationRunner runner(ReplyingKafkaTemplate<String, String, String> template) {
572
577
return args -> {
578
+
if (!template.waitForAssignment(Duration.ofSeconds(10))) {
579
+
throw new IllegalStateException("Reply container did not initialize");
580
+
}
573
581
ProducerRecord<String, String> record = new ProducerRecord<>("kRequests", "foo");
0 commit comments