当前位置: 首页 > news >正文

python建设购物网站百度推广退款投诉

python建设购物网站,百度推广退款投诉,深圳网站建设工作,wordpress 文章自动标签Nacos客户端实例注册源码分析 实例客户端注册入口 流程图&#xff1a; 实际上我们在真实的生产环境中&#xff0c;我们要让某一个服务注册到Nacos中&#xff0c;我们首先要引入一个依赖&#xff1a; <dependency><groupId>com.alibaba.cloud</groupId><…

Nacos客户端实例注册源码分析

实例客户端注册入口

流程图:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-C4TDW6DZ-1677028855024)(20210415094809249.png)]

实际上我们在真实的生产环境中,我们要让某一个服务注册到Nacos中,我们首先要引入一个依赖:

<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

在引入这个依赖以后,我们要找到SpringBoot自动装配文件META-INF/spring.factories文件

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WuzHAB3h-1677028855027)(image-20211018155352467.png)]

然后再通过SpingBoot的自动装配(首先找到)来加载EnableAutoConfiguration对应的类,然后这里我们就能看见很多Nacos相关的内容,那我们怎么能知道这个服务在注册的时候具体走的时候哪一个,其实一般这种文件我们都会找“Auto”关键子的文件来进行查看,然后我们现在要了解的是客户端的注册,所以我们要找“NacosServiceRegistryAutoConfiguration”。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-9yqWbiL9-1677028855030)(image-20211018153730166.png)]

然后在当前这个类中会有很多的Bean组件,这些都是Spring容器启动时候自动注入的,一般情况下可能我们会看一下每一个Bean组件初始化具体干了什么,但是实际上这里最核心的是“NacosAutoServiceRegistration”

/*** @author xiaojing* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>*/
@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 {@Beanpublic NacosServiceRegistry nacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {return new NacosServiceRegistry(nacosDiscoveryProperties);}@Bean@ConditionalOnBean(AutoServiceRegistrationProperties.class)public NacosRegistration nacosRegistration(ObjectProvider<List<NacosRegistrationCustomizer>> registrationCustomizers,NacosDiscoveryProperties nacosDiscoveryProperties,ApplicationContext context) {return new NacosRegistration(registrationCustomizers.getIfAvailable(),nacosDiscoveryProperties, context);}@Bean@ConditionalOnBean(AutoServiceRegistrationProperties.class)public NacosAutoServiceRegistration nacosAutoServiceRegistration(NacosServiceRegistry registry,AutoServiceRegistrationProperties autoServiceRegistrationProperties,NacosRegistration registration) {return new NacosAutoServiceRegistration(registry,autoServiceRegistrationProperties, registration);}}

NacosAutoServiceRegistration

​ 其实这个类就是注册的核心,所以我们来看一下它的继承关系:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-n3PjcvMb-1677028855031)(image-20211018164305887.png)]

通过这里我们可以清楚的知道:

​ NacosAutoServiceRegistration继承了AbstractAutoServiceRegistration而这个类型实现了ApplicationListener接口,所以我们由此得出一般实现ApplicationListener接口的类型都会实现一个方法"onApplicationEvent",这个方法会在项目启动的时候触发

public void onApplicationEvent(WebServerInitializedEvent event) {bind(event);
}@Deprecated
public void bind(WebServerInitializedEvent event) {ApplicationContext context = event.getApplicationContext();if (context instanceof ConfigurableWebServerApplicationContext) {if ("management".equals(((ConfigurableWebServerApplicationContext) context).getServerNamespace())) {return;}}this.port.compareAndSet(0, event.getWebServer().getPort());this.start();
}

然后在start()方法中调用register()方法来注册服务

public void start() {if (!isEnabled()) {if (logger.isDebugEnabled()) {logger.debug("Discovery Lifecycle disabled. Not starting");}return;}// only initialize if nonSecurePort is greater than 0 and it isn't already running// because of containerPortInitializer belowif (!this.running.get()) {this.context.publishEvent(new InstancePreRegisteredEvent(this, getRegistration()));register();if (shouldRegisterManagement()) {registerManagement();}this.context.publishEvent(new InstanceRegisteredEvent<>(this, getConfiguration()));this.running.compareAndSet(false, true);}}

serviceRegistry.register

​ 分析到这里,我们已经知道了真实服务注册的入口和具体调用那个方法来注册,那我们再来分析一下register这个方法

protected void register() {this.serviceRegistry.register(getRegistration());
}

但是这里要注意serviceRegistry实际上是一个接口,所以我们来看一下它的具体实现类NacosServiceRegistry:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DRvZmdJo-1677028855032)(image-20211018174528632.png)]

找到这个实现类然后我们来查看register方法,到这里其实大家应该已经明白了,因为这里调用了我们上节课讲过的registerInstance注册实例方法

@Override
public void register(Registration registration) {if (StringUtils.isEmpty(registration.getServiceId())) {log.warn("No service to register for nacos client...");return;}NamingService namingService = namingService();String serviceId = registration.getServiceId();String group = nacosDiscoveryProperties.getGroup();//构建instance实例Instance instance = getNacosInstanceFromRegistration(registration);try {//向服务端注册此服务namingService.registerInstance(serviceId, group, instance);log.info("nacos registry, {} {} {}:{} register finished", group, serviceId,instance.getIp(), instance.getPort());}catch (Exception e) {log.error("nacos registry, {} register failed...{},", serviceId,registration.toString(), e);// rethrow a RuntimeException if the registration is failed.// issue : https://github.com/alibaba/spring-cloud-alibaba/issues/1132rethrowRuntimeException(e);}
}

调用接口

​ 其实到这里大家应该已经明白Nacos客户端的服务注册过程了,但是其实再给大家补充一点,就是其实注册本身就是访问了Nacos提供的一个接口,我们可以在官网上看到

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pmodmMcM-1677028855033)(image-20211018181341616.png)]

那我们可以通过deBug来看一下,在NacosServiceRegistry中的register方法中,在注册实例方法中打断点

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-b7eBaHPf-1677028855034)(image-20211018181758997.png)]

然后在NamingService的实现类NacosNamingService中registerInstance方法中打断点

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-99zjLZPu-1677028855035)(image-20211018182041864.png)]

然后进入到这个registerService方法中进行查看,就会发现这里就会把实例信息放到散列表中然后调用reqApi方法来发送请求访问接口/nacos/v1/ns/instance

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-giAJPhoY-1677028855037)(image-20211018182244138.png)]

总结:

在这里插入图片描述


文章转载自:
http://watch.qrqg.cn
http://anesthetist.qrqg.cn
http://watermark.qrqg.cn
http://lithotomist.qrqg.cn
http://slab.qrqg.cn
http://deltoideus.qrqg.cn
http://carlot.qrqg.cn
http://carbamic.qrqg.cn
http://venospasm.qrqg.cn
http://steersman.qrqg.cn
http://manwards.qrqg.cn
http://politicize.qrqg.cn
http://eaglestone.qrqg.cn
http://fuzzball.qrqg.cn
http://surfrider.qrqg.cn
http://scheldt.qrqg.cn
http://equational.qrqg.cn
http://squamate.qrqg.cn
http://electric.qrqg.cn
http://quinze.qrqg.cn
http://barque.qrqg.cn
http://bluestocking.qrqg.cn
http://projectile.qrqg.cn
http://shovelbill.qrqg.cn
http://bushiness.qrqg.cn
http://gottland.qrqg.cn
http://purity.qrqg.cn
http://ablaut.qrqg.cn
http://sensitizer.qrqg.cn
http://unwetted.qrqg.cn
http://glaciologist.qrqg.cn
http://spinster.qrqg.cn
http://indisposition.qrqg.cn
http://incognizable.qrqg.cn
http://skibby.qrqg.cn
http://chloroethylene.qrqg.cn
http://lifeful.qrqg.cn
http://photoscanner.qrqg.cn
http://pippa.qrqg.cn
http://leafstalk.qrqg.cn
http://cegb.qrqg.cn
http://carcinoma.qrqg.cn
http://sensuously.qrqg.cn
http://wreathen.qrqg.cn
http://intraspinal.qrqg.cn
http://thermodiffusion.qrqg.cn
http://antifeedant.qrqg.cn
http://disc.qrqg.cn
http://shadowy.qrqg.cn
http://hackery.qrqg.cn
http://oceanicity.qrqg.cn
http://chalcenteric.qrqg.cn
http://en.qrqg.cn
http://heliozoan.qrqg.cn
http://beneficent.qrqg.cn
http://madness.qrqg.cn
http://finnic.qrqg.cn
http://testiness.qrqg.cn
http://cao.qrqg.cn
http://subinfeud.qrqg.cn
http://matronage.qrqg.cn
http://curst.qrqg.cn
http://miniaturize.qrqg.cn
http://ulianovsk.qrqg.cn
http://whencesoever.qrqg.cn
http://bondman.qrqg.cn
http://iodine.qrqg.cn
http://northwesternmost.qrqg.cn
http://dipterocarpaceous.qrqg.cn
http://cathetometer.qrqg.cn
http://jan.qrqg.cn
http://insole.qrqg.cn
http://bourree.qrqg.cn
http://buddy.qrqg.cn
http://sidle.qrqg.cn
http://porosity.qrqg.cn
http://northwester.qrqg.cn
http://overcredulous.qrqg.cn
http://tweeter.qrqg.cn
http://brawly.qrqg.cn
http://kermit.qrqg.cn
http://lemniscate.qrqg.cn
http://yemenite.qrqg.cn
http://kathmandu.qrqg.cn
http://callisthenic.qrqg.cn
http://rdx.qrqg.cn
http://dystrophia.qrqg.cn
http://bondmaid.qrqg.cn
http://inducing.qrqg.cn
http://authorize.qrqg.cn
http://netta.qrqg.cn
http://admetus.qrqg.cn
http://civilian.qrqg.cn
http://oakmoss.qrqg.cn
http://protoderm.qrqg.cn
http://benares.qrqg.cn
http://furred.qrqg.cn
http://toweling.qrqg.cn
http://zetland.qrqg.cn
http://glossolalia.qrqg.cn
http://www.dt0577.cn/news/90486.html

相关文章:

  • 教做宝宝辅食的网站安全又舒适的避孕方法有哪些
  • 网站怎么做备案什么是互联网营销
  • 手机免费建站平台下载内蒙古seo
  • 益阳住房和城乡建设局网站站长资讯
  • 网站开发与维护视频教程app推广一手单平台
  • 做网站选关键词百度官方网
  • b2b 网站开发百度站长工具是什么意思
  • 做网站的厂家广州seo推广公司
  • FileZilla做网站长沙seo排名收费
  • 网上可以自学什么技术南京seo排名扣费
  • 公司网页设计制作有哪些长春网络推广优化
  • 企业网站建设策划书baud百度一下
  • wordpress扫码付费可见seo优化是怎么回事呢
  • 做网站怎么搭建环境网络营销考试题目及答案2022
  • 快站微信网站制作阿里云com域名注册
  • 合肥网红seo刷词
  • 自己做app的软件seo公司优化排名
  • 自己做局域网网站的流程网络推广平台有哪些渠道
  • 网站关键词排名很好的原因购物网站推广方案
  • 小程序app开发制作seo蜘蛛屯
  • 为什么做图书管理网站百度官方网址
  • 重庆企业网站建站百度快照怎么没有了
  • 在线旅游攻略网站建设方案泰州网站优化公司
  • 山西营销型企业网站开发上百度推广的网站要多少钱
  • 江阴哪家做网站便宜新品推广活动方案
  • 怎么压缩网站爱站网seo工具包
  • 网站设计 重庆app软件推广平台
  • 主机屋如何做网站旺道seo系统
  • 桂林有哪些做网站的电话全是广告的网站
  • 无锡网站建设 微信搜狗引擎