Dubbo 启动加载流程、SPI流程
2021-11-03 17:36:19 0 举报
dubbo 流程图。主要是启动流程和SPI机制
作者其他创作
大纲/内容
ReferenceAnnotationBeanPostProcessor
启动流程简化版:SpringBoot 启动Dubbo
loadResource
@EnableDubboConfig
ImportBeanDefinitionRegistrar
ApplicationListener<ServiceBeanExportedEvent>
启动流程:SpringBoot 启动Dubbo
ConfigurationBeanBindingsRegister
//解析配置文件,转换成AnnotationAttributes,注册到beanDefinitionMap
DynamicConfiguration
getDefaultExtension()
containsKey(name)
将配置解析class和注解解析class注册到beanDefinitionMap
getExtensionClasses()
publishEvent(new ContextRefreshedEvent(this));
DubboBootstrapApplicationListener
DubboComponentScanRegistrar
DubboBootstrap
initialize
先尝试从缓存加载,加载不到的话就调用文件系统读取SPI文件内容
AbstractApplicationContext
refresh()
ServiceAnnotationBeanPostProcessor
finishRefresh();
containsExtension(name)
启动时加载配置解析组件:配置解析,注解解析等
loadDirectory
Dubbo SPI:SPI的实现流程
Dubbo SPI:注册中心对SPI的调用
loadClass
BeanDefinitionRegistryPostProcessors
使用class全路径名获取SPI文件内容
DubboConfigConfigurationRegistrar
# 将配置解析相关的class注册到beanDefinitionMapDubboConfigConfiguration.Single.classDubboConfigConfiguration.Multiple.classReferenceAnnotationBeanPostProcessor.classConfigurationBeanBindingsRegister.class……
AbstractAnnotationBeanPostProcessor
处理@Reference 注解,Dubbo自己写了一套注入(inject)代码,将代理对象注入到Bean 属性
finishBeanFactoryInitialization(beanFactory);
ServiceClassPostProcessor
//解析DubboService 相关注解,将Bean注册到beanDefinitionMap
@DubboComponentScan
createBean
BeanDefinitionRegistryPostProcessor
invokeBeanFactoryPostProcessors(beanFactory);
populateBean
判断在SPI中能否取到name对应的类
getExtension(name)
useRegistryAsConfigCenterIfNecessary
# 将dubbo服务解析相关的class注册到beanDefinitionMapServiceAnnotationBeanPostProcessor.classReferenceAnnotationBeanPostProcessor.class……
ExtensionLoader
public T getOrDefaultExtension(String name) { return containsExtension(name) ? getExtension(name) : getDefaultExtension(); }
@EnableDubbo
InstantiationAwareBeanPostProcessorAdapter
//@Reference 注解的后置处理器,目的是将RPC代理对象注入IOC 中
无法获取到
可以取到
createExtension
ConfigurationClassPostProcessor
使用解析器将解析的Bean注册到beanDefinitionMap
扩展点
startConfigCenter(){ ...... if (CollectionUtils.isNotEmpty(configCenters)) { CompositeDynamicConfiguration compositeDynamicConfiguration = new CompositeDynamicConfiguration(); for (ConfigCenterConfig configCenter : configCenters) { compositeDynamicConfiguration.addConfiguration(prepareEnvironment(configCenter)); } environment.setDynamicConfiguration(compositeDynamicConfiguration); } configManager.refreshAll();}
loadExtensionClasses
反射调用类的实例并缓存起来
//导出Dubbo服务,用到了SPIexportServices();//对缓存的ReferenceConfig 进行处理referServices();
saveInExtensionClass
Dubbo启动类,这里主要是暴露服务(基于SPI),对缓存的referenceConfig 做最后的配置
DynamicConfigurationFactory
static DynamicConfigurationFactory getDynamicConfigurationFactory(String name) { Class<DynamicConfigurationFactory> factoryClass = DynamicConfigurationFactory.class; ExtensionLoader<DynamicConfigurationFactory> loader = getExtensionLoader(factoryClass); return loader.getOrDefaultExtension(name); }
0 条评论
下一页