Skip to content

Commit 1415774

Browse files
committed
ReplyingKafkaTemplate Polishing
- use lastHeader instead of iterator to find the reply topic header
1 parent 6f8127a commit 1415774

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

spring-kafka/src/main/java/org/springframework/kafka/requestreply/ReplyingKafkaTemplate.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,8 @@ public RequestReplyFuture<K, V, R> sendAndReceive(ProducerRecord<K, V> record) {
246246
Assert.state(this.running, "Template has not been start()ed"); // NOSONAR (sync)
247247
CorrelationKey correlationId = this.correlationStrategy.apply(record);
248248
Assert.notNull(correlationId, "the created 'correlationId' cannot be null");
249-
boolean hasReplyTopic = false;
250249
Headers headers = record.headers();
251-
Iterator<Header> iterator = headers.iterator();
252-
while (iterator.hasNext() && !hasReplyTopic) {
253-
if (iterator.next().key().equals(KafkaHeaders.REPLY_TOPIC)) {
254-
hasReplyTopic = true;
255-
}
256-
}
250+
boolean hasReplyTopic = headers.lastHeader(KafkaHeaders.REPLY_TOPIC) != null;
257251
if (!hasReplyTopic && this.replyTopic != null) {
258252
headers.add(new RecordHeader(KafkaHeaders.REPLY_TOPIC, this.replyTopic));
259253
if (this.replyPartition != null) {

0 commit comments

Comments
 (0)