|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2017 the original author or authors. |
| 2 | + * Copyright 2016-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.lang.reflect.Method;
|
20 | 20 | import java.util.Arrays;
|
21 | 21 |
|
| 22 | +import org.apache.commons.logging.Log; |
| 23 | +import org.apache.commons.logging.LogFactory; |
| 24 | + |
22 | 25 | import org.springframework.core.annotation.AnnotationUtils;
|
23 | 26 | import org.springframework.kafka.listener.KafkaListenerErrorHandler;
|
24 | 27 | import org.springframework.kafka.listener.MessageListenerContainer;
|
|
48 | 51 | */
|
49 | 52 | public class MethodKafkaListenerEndpoint<K, V> extends AbstractKafkaListenerEndpoint<K, V> {
|
50 | 53 |
|
| 54 | + private final Log logger = LogFactory.getLog(getClass()); |
| 55 | + |
51 | 56 | private Object bean;
|
52 | 57 |
|
53 | 58 | private Method method;
|
@@ -105,6 +110,9 @@ private String getReplyTopic() {
|
105 | 110 | if (method != null) {
|
106 | 111 | SendTo ann = AnnotationUtils.getAnnotation(method, SendTo.class);
|
107 | 112 | if (ann != null) {
|
| 113 | + if (method.getReturnType().equals(void.class)) { |
| 114 | + this.logger.warn("Method has a void return type; @SendTo is ignored"); |
| 115 | + } |
108 | 116 | String[] destinations = ann.value();
|
109 | 117 | if (destinations.length > 1) {
|
110 | 118 | throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
|
@@ -132,7 +140,7 @@ protected MessagingMessageListenerAdapter<K, V> createMessageListener(MessageLis
|
132 | 140 | MessagingMessageListenerAdapter<K, V> messageListener = createMessageListenerInstance(messageConverter);
|
133 | 141 | messageListener.setHandlerMethod(configureListenerAdapter(messageListener));
|
134 | 142 | String replyTopic = getReplyTopic();
|
135 |
| - if (replyTopic != null) { |
| 143 | + if (replyTopic != null && !getMethod().getReturnType().equals(void.class)) { |
136 | 144 | Assert.state(getReplyTemplate() != null, "a KafkaTemplate is required to support replies");
|
137 | 145 | messageListener.setReplyTopic(replyTopic);
|
138 | 146 | }
|
|
0 commit comments