Skip to content

Commit

Permalink
GH-946: Detect Unnecessary Replying Template
Browse files Browse the repository at this point in the history
Resolves #946
  • Loading branch information
garyrussell authored and artembilan committed Feb 8, 2019
1 parent ee24000 commit c5b2ee4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -21,6 +21,9 @@
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;
Expand All @@ -35,6 +38,7 @@
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;
Expand All @@ -57,6 +61,8 @@
public abstract class AbstractKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K, V>, K, V>
implements KafkaListenerContainerFactory<C>, ApplicationEventPublisherAware, InitializingBean {

protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR protected

private final ContainerProperties containerProperties = new ContainerProperties((Pattern) null);

private GenericErrorHandler<?> errorHandler;
Expand Down Expand Up @@ -203,6 +209,13 @@ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEv
* @since 2.0
*/
public void setReplyTemplate(KafkaTemplate<?, ?> 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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/reference/asciidoc/kafka.adoc
Expand Up @@ -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:
Expand Down

0 comments on commit c5b2ee4

Please sign in to comment.