暴露服務(wù)睁宰。類似平時網(wǎng)絡(luò)編程寫server肪获,需要打開socket,監(jiān)聽端口等柒傻。只不過RPC有整套的封裝贪磺。下面我們通過斷點跟隨源碼,梳理下整個流程诅愚。
采用某種技術(shù)(spring寒锚?)獲取到服務(wù)相關(guān)的所有配置后,就到了暴露服務(wù)的入口函數(shù)ServiceBean.afterPropertiesSet违孝,接下來的調(diào)用鏈條是:
ServiceConfig.export ->
ServiceConfig.doExport ->
ServiceConfig.doExportUrls->
ServiceConfig.doExportUrlsFor1Protocol
ProxyFactory.getInvoker(ref, (Class) interfaceClass, url) // 獲得invoker
Protocol.export(invoker) // 暴露服務(wù)刹前?
Exchangers.bind(url, requestHandler) //
Transporters.bind(url, handler)
NettyTransporter.bind(url, ChannelHandler)
NettyServer.dopen()
相關(guān)細(xì)節(jié)分析
- ProtocolListenerWrapper 和 ProtocolFilterWrapper(串聯(lián)filter調(diào)用鏈)
- spring加載啟動一大堆
- ProxyFactory.getInvoker(ref, (Class) interfaceClass, url)
相關(guān)技術(shù)點:動態(tài)代理技術(shù),代理模式
- 裝飾模式
服務(wù)暴露前的注冊:創(chuàng)建同注冊中心的鏈接雌桑,然后再走真正的服務(wù)協(xié)議暴露流程喇喉。 Protocol利用裝飾模式的體現(xiàn):RegistryProtocol對Protocol的包裝
- Protocol.export相關(guān)流程