你应该考虑在
@EnableAspectJAutoProxy
以下内容:
/**
* Indicate that the proxy should be exposed by the AOP framework as a {@code ThreadLocal}
* for retrieval via the {@link org.springframework.aop.framework.AopContext} class.
* Off by default, i.e. no guarantees that {@code AopContext} access will work.
* @since 4.3.1
*/
boolean exposeProxy() default false;
另一方面,有这样的事情,这将比aop更好:
/**
* A plugin interface that allows you to intercept (and possibly mutate) records received by the consumer. A primary use-case
* is for third-party components to hook into the consumer applications for custom monitoring, logging, etc.
*
* <p>
* This class will get consumer config properties via <code>configure()</code> method, including clientId assigned
* by KafkaConsumer if not specified in the consumer config. The interceptor implementation needs to be aware that it will be
* sharing consumer config namespace with other interceptors and serializers, and ensure that there are no conflicts.
* <p>
* Exceptions thrown by ConsumerInterceptor methods will be caught, logged, but not propagated further. As a result, if
* the user configures the interceptor with the wrong key and value type parameters, the consumer will not throw an exception,
* just log the errors.
* <p>
* ConsumerInterceptor callbacks are called from the same thread that invokes {@link org.apache.kafka.clients.consumer.KafkaConsumer#poll(long)}.
* <p>
* Implement {@link org.apache.kafka.common.ClusterResourceListener} to receive cluster metadata once it's available. Please see the class documentation for ClusterResourceListener for more information.
*/
public interface ConsumerInterceptor<K, V> extends Configurable {
更新
@EnableAspectJAutoProxy(exposeProxy=true)
没有工作,我知道我可以使用拦截器,但我想让它与aop一起工作。
那么我建议你考虑
DepartmentsMessageConsumer
以及
ConcurrentMessageListenerContainer
是的。我是说把它挪开
ConcurrentMessageListenerContainer
分开的
@Configuration
上课。这个
ApplicationLauncher
是一个很好的候选人。作为一个
@Bean
依赖于你的
部门信息消费者
注射用。关键是你需要给一个AOP一个机会
部门信息消费者
,但是
@PostConstruct
,现在从卡夫卡实例化并开始消费还为时过早。