調用層
RabbitAutoConfiguration
// 這個是自動配置引入
RabbitAnnotationDrivenConfiguration
@EnableRabbit
RabbitBootstrapConfiguration
RabbitListenerAnnotationBeanPostProcessor
- xx 略
- 說明:
- 加
@RabbitListener
註解的類本身沒有被 AOP 代理
- 只是 Spring 內部記錄下
- 然後收到消息通過反射調用被註解的方法
- 類似 SpringMVC 對
@RequestMapping
映射的處理
最終調用
SimpleMessageListenerContainer.AsyncMessageProcessingConsumer
循環監聽
receiveAndExecute(this.consumer)
類似 socket 阻塞式監聽
BlockingQueueConsumer
- 內部再是通過阻塞隊列,實現生產者、消費者模式
- 默認
1
秒試拉 1
次
MessagingMessageListenerAdapter
具體調用
測試 AOP 導出
static void setProxySavePath() throws Exception {
System.setProperty( "jdk.proxy.ProxyGenerator.saveGeneratedFiles", "true" );
Path path = Paths.get( Consumer1MainApplication.class.getResource( "/" ).toURI() );
Path savePath = path.resolve( "../export/spring-aop-proxy" )
.normalize()
.toAbsolutePath();
Files.createDirectories( savePath );
System.out.println( "class 存放路徑:" );
System.out.println( savePath );
System.out.println( "----------------------" );
// 設置將 cglib 生成的代理類字節碼生成到指定位置
System.setProperty( DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, savePath.toString() );
}
最後
看源碼的一些忠告
- 用 IDEA 看源碼,查看被調用的地方比較方便
- 用 Eclipse 看被調用的點時,有時很坑