Python----多继承和MRO继承机制
385
2022-08-23
SpringCloud 服务注册中的nacos实现过程
如下图,org.springframework.cloud.spring-cloud-commons包下定义了一系列接口,其中就包括serviceregistry的系列规范,并通过SPI机制去调用接口实现。
在该包的META-INF/spring.factories文件中,可以找到EnableAutoConfiguration.class为key的value中有AutoServiceRegistrationAutoConfiguration.class这一项。
来看看这个AutoServiceRegistrationAutoConfiguration配置类:
对应的,在com.alibaba.cloud.nacos包下(位于spring-cloud-starter-nacos-discovery jar包中)的META-INF/spring.fatories有个nacos服务注册配置类,如下图:
这个NacosServiceRegistryAutoConfiguration 配置类就定义了上面SpringCloud的AutoServiceRegistration接口的实现类:
package com.alibaba.cloud.nacos.registry;
...
/**
* @author xiaojing
* @author Mercy
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ConditionalOnNacosDiscoveryEnabled
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled",
matchIfMissing = true)
@AutoConfigureAfter({ AutoServiceRegistrationConfiguration.class,
AutoServiceRegistrationAutoConfiguration.class,
NacosDiscoveryAutoConfiguration.class })
public class NacosServiceRegistryAutoConfiguration {
@Bean
public NacosServiceRegistry nacosServiceRegistry(
NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosServiceRegistry(nacosDiscoveryProperties);
}
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration(
ObjectProvider> registrationCustomizers,
NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) {
return new NacosRegistration(registrationCustomizers.getIfAvailable(),
nacosDiscoveryProperties, context);
}
/**
** 这里,这个NacosAutoServiceRegistration就是AutoServiceRegistration接口的实现类
**/
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceuQjdKedISxRegistrationProperties,
NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration);
}
}
NacosAutoServiceRegistration中的register()方法开始注册服务,整个调用流程为:
继续追根溯源,这个registry()方法是在AbstractAutoServiceRegistration implements ApplicationListener
另外上面最后一步的NamingClientProxy接口的实现如下,利用到了委托模式(delegate)也叫代理模式?:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~