1. SOFA RPC源码解析
1.1 SOFA RPC服务发布、引用、调用和响应流程
1.1.1 服务发布流程
对于不同类型的SOFABoot服务,如Jvm服务、Rest服务、Bolt服务或Dubbo服务,服务发布的主流程如下:
1. 定义SOFABoot服务:
- 在SpringXML文件中使用标签sofa-service定义服务;
- 在Java类中使用注解@SofaService定义服务;
- 在Java类中使用ServiceParam定义服务。
2. 解析SOFABoot服务:
- 使用ServiceDefinitionParser解析SpringXML文件中标签sofa-service,转换为ServiceFactoryBean;
- 使用ServiceAnnotationBeanPostProcessor处理注解@SofaService;
- 使用ServiceClientImpl处理ServiceParam。
3. 创建服务组件:
- 在ServiceFactoryBean类afterPropertiesSet方法中,处理SOFABoot服务相关的配置,最终创建服务组件ServiceComponent;
- 在ServiceAnnotationBeanPostProcessor类processSofaService方法中,处理SOFABoot服务相关的配置,最终创建服务组件ServiceComponent;
- 在ServiceClientImpl类service方法中,处理SOFABoot服务相关的配置,最终创建服务组件ServiceComponent。
4.注册服务组件:
在组件管理器ComponentManagerImpl中注册服务组件ServiceComponent:
- 调用组件ServiceComponent类的register方法,更新组件状态为registered
- 调用组件ServiceComponent类的resolve方法,更新组件状态为resolved;
- 调用组件ServiceComponent的activate方法,更新组件状态为activated。
5. 激活服务组件:
把组件状态改为activated之前,需要调用activateBinding方法激活组件。
6. 发布SOFABoot服务-BindingAdapter:
在activateBinding方法中,针对SOFABoot服务的服务类型,使用相应的BindingAdapter接口实现(如: