|
49 | 49 | import javax.validation.ValidationException; |
50 | 50 | import javax.validation.constraints.Max; |
51 | 51 |
|
| 52 | +import org.aopalliance.intercept.MethodInterceptor; |
| 53 | +import org.aopalliance.intercept.MethodInvocation; |
52 | 54 | import org.apache.commons.logging.Log; |
53 | 55 | import org.apache.commons.logging.LogFactory; |
54 | 56 | import org.apache.kafka.clients.admin.NewTopic; |
|
67 | 69 | import org.junit.jupiter.api.Test; |
68 | 70 | import org.mockito.Mockito; |
69 | 71 |
|
| 72 | +import org.springframework.aop.framework.ProxyFactory; |
| 73 | +import org.springframework.beans.BeansException; |
70 | 74 | import org.springframework.beans.factory.ObjectProvider; |
71 | 75 | import org.springframework.beans.factory.annotation.Autowired; |
| 76 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 77 | +import org.springframework.beans.factory.config.BeanPostProcessor; |
72 | 78 | import org.springframework.context.annotation.Bean; |
73 | 79 | import org.springframework.context.annotation.Configuration; |
74 | 80 | import org.springframework.context.annotation.Primary; |
| 81 | +import org.springframework.context.annotation.Role; |
75 | 82 | import org.springframework.context.event.EventListener; |
76 | 83 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; |
77 | 84 | import org.springframework.core.MethodParameter; |
| 85 | +import org.springframework.core.Ordered; |
| 86 | +import org.springframework.core.annotation.Order; |
78 | 87 | import org.springframework.core.convert.converter.Converter; |
79 | 88 | import org.springframework.data.web.JsonPath; |
80 | 89 | import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; |
|
168 | 177 | "annotated25", "annotated25reply1", "annotated25reply2", "annotated26", "annotated27", "annotated28", |
169 | 178 | "annotated29", "annotated30", "annotated30reply", "annotated31", "annotated32", "annotated33", |
170 | 179 | "annotated34", "annotated35", "annotated36", "annotated37", "foo", "manualStart", "seekOnIdle", |
171 | | - "annotated38", "annotated38reply", "annotated39"}) |
| 180 | + "annotated38", "annotated38reply", "annotated39", "sentto-in", "sendto-out"}) |
172 | 181 | public class EnableKafkaIntegrationTests { |
173 | 182 |
|
174 | 183 | private static final String DEFAULT_TEST_GROUP_ID = "testAnnot"; |
@@ -1277,6 +1286,13 @@ public IfaceListener<String> ifaceListener() { |
1277 | 1286 | return new IfaceListenerImpl(); |
1278 | 1287 | } |
1279 | 1288 |
|
| 1289 | + @Bean |
| 1290 | + @Order(Ordered.HIGHEST_PRECEDENCE) |
| 1291 | + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
| 1292 | + public ProxyListenerPostProcessor proxyListenerPostProcessor() { |
| 1293 | + return new ProxyListenerPostProcessor(); |
| 1294 | + } |
| 1295 | + |
1280 | 1296 | @Bean |
1281 | 1297 | public MultiListenerBean multiListener() { |
1282 | 1298 | return new MultiListenerBean(); |
@@ -2001,6 +2017,27 @@ public void registerSeekCallback(ConsumerSeekCallback callback) { |
2001 | 2017 |
|
2002 | 2018 | } |
2003 | 2019 |
|
| 2020 | + static class ProxyListenerPostProcessor implements BeanPostProcessor { |
| 2021 | + |
| 2022 | + @Override |
| 2023 | + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { |
| 2024 | + if ("multiListenerSendTo".equals(beanName)) { |
| 2025 | + ProxyFactory proxyFactory = new ProxyFactory(bean); |
| 2026 | + proxyFactory.setProxyTargetClass(true); |
| 2027 | + proxyFactory.addAdvice(new MethodInterceptor() { |
| 2028 | + @Override |
| 2029 | + public Object invoke(MethodInvocation invocation) throws Throwable { |
| 2030 | + logger.info(String.format("Proxy listener for %s.$s", |
| 2031 | + invocation.getMethod().getDeclaringClass(), invocation.getMethod().getName())); |
| 2032 | + return invocation.proceed(); |
| 2033 | + } |
| 2034 | + }); |
| 2035 | + return proxyFactory.getProxy(); |
| 2036 | + } |
| 2037 | + return bean; |
| 2038 | + } |
| 2039 | + } |
| 2040 | + |
2004 | 2041 | public static class SeekToLastOnIdleListener extends AbstractConsumerSeekAware { |
2005 | 2042 |
|
2006 | 2043 | private final CountDownLatch latch1 = new CountDownLatch(10); |
|
0 commit comments