|
47 | 47 | import javax.validation.ValidationException; |
48 | 48 | import javax.validation.constraints.Max; |
49 | 49 |
|
| 50 | +import org.aopalliance.intercept.MethodInterceptor; |
| 51 | +import org.aopalliance.intercept.MethodInvocation; |
| 52 | +import org.apache.commons.logging.Log; |
| 53 | +import org.apache.commons.logging.LogFactory; |
50 | 54 | import org.apache.kafka.clients.admin.NewTopic; |
51 | 55 | import org.apache.kafka.clients.consumer.Consumer; |
52 | 56 | import org.apache.kafka.clients.consumer.ConsumerConfig; |
|
62 | 66 | import org.junit.jupiter.api.Test; |
63 | 67 | import org.mockito.Mockito; |
64 | 68 |
|
| 69 | +import org.springframework.aop.framework.ProxyFactory; |
| 70 | +import org.springframework.beans.BeansException; |
65 | 71 | import org.springframework.beans.factory.ObjectProvider; |
66 | 72 | import org.springframework.beans.factory.annotation.Autowired; |
| 73 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 74 | +import org.springframework.beans.factory.config.BeanPostProcessor; |
67 | 75 | import org.springframework.context.annotation.Bean; |
68 | 76 | import org.springframework.context.annotation.Configuration; |
69 | 77 | import org.springframework.context.annotation.Primary; |
| 78 | +import org.springframework.context.annotation.Role; |
70 | 79 | import org.springframework.context.event.EventListener; |
71 | 80 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
72 | 81 | import org.springframework.core.MethodParameter; |
| 82 | +import org.springframework.core.Ordered; |
| 83 | +import org.springframework.core.annotation.Order; |
73 | 84 | import org.springframework.core.convert.converter.Converter; |
74 | 85 | import org.springframework.data.web.JsonPath; |
75 | 86 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; |
|
163 | 174 | "annotated38", "annotated38reply", "annotated39"}) |
164 | 175 | public class EnableKafkaIntegrationTests { |
165 | 176 |
|
| 177 | + private static final Log logger = LogFactory.getLog(EnableKafkaIntegrationTests.class); |
| 178 | + |
166 | 179 | private static final String DEFAULT_TEST_GROUP_ID = "testAnnot"; |
167 | 180 |
|
168 | 181 | @Autowired |
@@ -1218,6 +1231,13 @@ public IfaceListener<String> ifaceListener() { |
1218 | 1231 | return new IfaceListenerImpl(); |
1219 | 1232 | } |
1220 | 1233 |
|
| 1234 | + @Bean |
| 1235 | + @Order(Ordered.HIGHEST_PRECEDENCE) |
| 1236 | + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
| 1237 | + public ProxyListenerPostProcessor proxyListenerPostProcessor() { |
| 1238 | + return new ProxyListenerPostProcessor(); |
| 1239 | + } |
| 1240 | + |
1221 | 1241 | @Bean |
1222 | 1242 | public MultiListenerBean multiListener() { |
1223 | 1243 | return new MultiListenerBean(); |
@@ -1936,6 +1956,27 @@ public void registerSeekCallback(ConsumerSeekCallback callback) { |
1936 | 1956 |
|
1937 | 1957 | } |
1938 | 1958 |
|
| 1959 | + static class ProxyListenerPostProcessor implements BeanPostProcessor { |
| 1960 | + |
| 1961 | + @Override |
| 1962 | + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
| 1963 | + if ("multiListenerSendTo".equals(beanName)) { |
| 1964 | + ProxyFactory proxyFactory = new ProxyFactory(bean); |
| 1965 | + proxyFactory.setProxyTargetClass(true); |
| 1966 | + proxyFactory.addAdvice(new MethodInterceptor() { |
| 1967 | + @Override |
| 1968 | + public Object invoke(MethodInvocation invocation) throws Throwable { |
| 1969 | + logger.info(String.format("Proxy listener for %s.$s", |
| 1970 | + invocation.getMethod().getDeclaringClass(), invocation.getMethod().getName())); |
| 1971 | + return invocation.proceed(); |
| 1972 | + } |
| 1973 | + }); |
| 1974 | + return proxyFactory.getProxy(); |
| 1975 | + } |
| 1976 | + return bean; |
| 1977 | + } |
| 1978 | + } |
| 1979 | + |
1939 | 1980 | public static class SeekToLastOnIdleListener extends AbstractConsumerSeekAware { |
1940 | 1981 |
|
1941 | 1982 | private final CountDownLatch latch1 = new CountDownLatch(10); |
|
0 commit comments