如何向 RabbitListener 添加 Around Advice
How to Add an Around Advice to RabbitListener
针对
的提问和回答
添加一个 MethodInterceptor
bean 并将其连接到容器工厂:
@Bean
MethodInterceptor interceptor(AbstractRabbitListenerContainerFactory<AbstractMessageListenerContainer> factory) {
MethodInterceptor inter = invocation -> {
try {
// do something before
return invocation.proceed();
}
finally {
// do something after
}
};
factory.setAdviceChain(inter);
return inter;
}
针对
添加一个 MethodInterceptor
bean 并将其连接到容器工厂:
@Bean
MethodInterceptor interceptor(AbstractRabbitListenerContainerFactory<AbstractMessageListenerContainer> factory) {
MethodInterceptor inter = invocation -> {
try {
// do something before
return invocation.proceed();
}
finally {
// do something after
}
};
factory.setAdviceChain(inter);
return inter;
}