|
16 | 16 |
|
17 | 17 | package org.springframework.kafka.requestreply; |
18 | 18 |
|
19 | | -import java.nio.ByteBuffer; |
20 | | -import java.nio.charset.StandardCharsets; |
21 | | -import java.time.Duration; |
22 | | -import java.time.Instant; |
23 | | -import java.util.Collection; |
24 | | -import java.util.List; |
25 | | -import java.util.UUID; |
26 | | -import java.util.concurrent.ConcurrentHashMap; |
27 | | -import java.util.concurrent.ConcurrentMap; |
28 | | -import java.util.concurrent.CountDownLatch; |
29 | | -import java.util.concurrent.TimeUnit; |
30 | | -import java.util.function.Function; |
31 | | - |
32 | 19 | import io.micrometer.observation.Observation; |
33 | 20 | import org.apache.kafka.clients.consumer.ConsumerRecord; |
34 | 21 | import org.apache.kafka.clients.producer.ProducerRecord; |
|
37 | 24 | import org.apache.kafka.common.header.Headers; |
38 | 25 | import org.apache.kafka.common.header.internals.RecordHeader; |
39 | 26 | import org.jspecify.annotations.Nullable; |
40 | | - |
41 | 27 | import org.springframework.beans.factory.DisposableBean; |
42 | 28 | import org.springframework.beans.factory.InitializingBean; |
43 | 29 | import org.springframework.context.SmartLifecycle; |
|
62 | 48 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
63 | 49 | import org.springframework.util.Assert; |
64 | 50 |
|
| 51 | +import java.nio.ByteBuffer; |
| 52 | +import java.nio.charset.StandardCharsets; |
| 53 | +import java.time.Duration; |
| 54 | +import java.time.Instant; |
| 55 | +import java.util.Collection; |
| 56 | +import java.util.List; |
| 57 | +import java.util.Optional; |
| 58 | +import java.util.UUID; |
| 59 | +import java.util.concurrent.ConcurrentHashMap; |
| 60 | +import java.util.concurrent.ConcurrentMap; |
| 61 | +import java.util.concurrent.CountDownLatch; |
| 62 | +import java.util.concurrent.TimeUnit; |
| 63 | +import java.util.function.Function; |
| 64 | + |
65 | 65 | /** |
66 | 66 | * A KafkaTemplate that implements request/reply semantics. |
67 | 67 | * |
|
73 | 73 | * @author Artem Bilan |
74 | 74 | * @author Borahm Lee |
75 | 75 | * @author Francois Rosiere |
| 76 | + * @author Mikhail Polivakha |
76 | 77 | * |
77 | 78 | * @since 2.1.3 |
78 | 79 | * |
@@ -415,14 +416,11 @@ public RequestReplyFuture<K, V, R> sendAndReceive(ProducerRecord<K, V> record) { |
415 | 416 | @Override |
416 | 417 | public RequestReplyFuture<K, V, R> sendAndReceive(ProducerRecord<K, V> record, @Nullable Duration replyTimeout) { |
417 | 418 | Assert.state(this.running, "Template has not been started"); // NOSONAR (sync) |
418 | | - Duration timeout = replyTimeout; |
419 | | - if (timeout == null) { |
420 | | - timeout = this.defaultReplyTimeout; |
421 | | - } |
| 419 | + Duration timeout = Optional.ofNullable(replyTimeout).orElse(defaultReplyTimeout); |
422 | 420 | CorrelationKey correlationId = this.correlationStrategy.apply(record); |
423 | 421 | Assert.notNull(correlationId, "the created 'correlationId' cannot be null"); |
424 | 422 | Headers headers = record.headers(); |
425 | | - boolean hasReplyTopic = headers.lastHeader(KafkaHeaders.REPLY_TOPIC) != null; |
| 423 | + boolean hasReplyTopic = headers.lastHeader(this.replyTopicHeaderName) != null; |
426 | 424 | if (!hasReplyTopic && this.replyTopic != null) { |
427 | 425 | headers.add(new RecordHeader(this.replyTopicHeaderName, this.replyTopic)); |
428 | 426 | if (this.replyPartition != null) { |
|
0 commit comments