From c5b2ee47cb13d60357794e5bb1aeaa6fd1ede726 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 8 Feb 2019 12:49:33 -0500 Subject: [PATCH] GH-946: Detect Unnecessary Replying Template Resolves https://github.com/spring-projects/spring-kafka/issues/946 --- .../AbstractKafkaListenerContainerFactory.java | 13 +++++++++++++ src/reference/asciidoc/kafka.adoc | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java b/spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java index c7e46687..2558c2fe 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/config/AbstractKafkaListenerContainerFactory.java @@ -21,6 +21,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.regex.Pattern; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationEventPublisher; @@ -35,6 +38,7 @@ import org.springframework.kafka.listener.ErrorHandler; import org.springframework.kafka.listener.GenericErrorHandler; import org.springframework.kafka.listener.adapter.RecordFilterStrategy; import org.springframework.kafka.listener.adapter.ReplyHeadersConfigurer; +import org.springframework.kafka.requestreply.ReplyingKafkaOperations; import org.springframework.kafka.support.TopicPartitionInitialOffset; import org.springframework.kafka.support.converter.MessageConverter; import org.springframework.retry.RecoveryCallback; @@ -57,6 +61,8 @@ import org.springframework.util.Assert; public abstract class AbstractKafkaListenerContainerFactory, K, V> implements KafkaListenerContainerFactory, ApplicationEventPublisherAware, InitializingBean { + protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR protected + private final ContainerProperties containerProperties = new ContainerProperties((Pattern) null); private GenericErrorHandler errorHandler; @@ -203,6 +209,13 @@ public abstract class AbstractKafkaListenerContainerFactory replyTemplate) { + if (replyTemplate instanceof ReplyingKafkaOperations) { + this.logger.warn( + "The 'replyTemplate' should not be an implementation of 'ReplyingKafkaOperations'; " + + "such implementations are for client-side request/reply operations; here we " + + "are simply sending a reply to an incoming request so the reply container will " + + "never be used and will consume unnecessary resources."); + } this.replyTemplate = replyTemplate; } diff --git a/src/reference/asciidoc/kafka.adoc b/src/reference/asciidoc/kafka.adoc index 0454f64a..3e0bbbed 100644 --- a/src/reference/asciidoc/kafka.adoc +++ b/src/reference/asciidoc/kafka.adoc @@ -735,7 +735,7 @@ Aside from the logs, there was no indication that there was a problem. To restore the previous behavior, you canset the property to `false`. [[using-ConcurrentMessageListenerContainer]] -====== Using`ConcurrentMessageListenerContainer` +====== Using `ConcurrentMessageListenerContainer` The single constructor is similar to the first `KafkaListenerContainer` constructor. The following listing shows the constructor's signature: