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

网站标题能改吗免费网站设计工具

网站标题能改吗,免费网站设计工具,支付网站建设费,上海设计网站Nacos客户端入口 首先在我们使用Nacos时#xff0c;会在客户端引入对应的依赖#xff0c;例如需要Nacos的注册中心功能需要引入 !--nacos-discovery 注册中心依赖--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-c…Nacos客户端入口 首先在我们使用Nacos时会在客户端引入对应的依赖例如需要Nacos的注册中心功能需要引入 !--nacos-discovery 注册中心依赖--dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency而熟悉Springboot的自然知道为什么引用一个starter就能引入对应的功能这离不开Springboot的自动配置功能这也是其特点之一。 而说到自动配置那自然离不开自动配置类他即是功能的入口。 那Nacos有哪些自动配置类呢 NacosServiceAutoConfiguration 这是Nacos服务器通信的基础设施是整个 Nacos 集成的连接管理中心。 Configuration(proxyBeanMethods false ) ConditionalOnDiscoveryEnabled ConditionalOnNacosDiscoveryEnabled public class NacosServiceAutoConfiguration {public NacosServiceAutoConfiguration() {}Beanpublic NacosServiceManager nacosServiceManager() {return new NacosServiceManager();}// Spring 应用 → NacosServiceManager → Nacos SDK → Nacos 服务器}NacosServiceManager 被多个 Nacos 相关组件使用: 服务发现组件: NacosServiceDiscovery 使用它获取 NamingService 实例 NacosRegistration 使用它进行服务注册 配置中心组件: NacosConfigManager 使用它获取 ConfigService 实例 配置刷新机制依赖它提供的服务对象 延迟初始化: NacosServiceManager 不会在创建时立即连接 Nacos 服务器而是采用延迟初始化策略 按需创建服务对象: 当系统需要 NamingService (服务发现) 时按需创建并缓存 当系统需要 ConfigService (配置中心) 时按需创建并缓存 服务对象缓存机制: 基于属性如命名空间、分组创建缓存键 相同配置的服务请求复用同一个服务对象实例 避免重复创建连接优化资源使用 生命周期管理: 与 Spring 容器生命周期绑定 在应用关闭时释放资源、关闭连接 NacosDiscoveryAutoConfiguration 这是Nacos的服务发现自动配置类主要有如下功能 自动装配 Nacos 服务发现组件初始化服务发现相关的基础设施 Bean使应用能够与 Nacos 服务器进行服务注册与发现交互 Configuration(proxyBeanMethods false ) ConditionalOnDiscoveryEnabled ConditionalOnNacosDiscoveryEnabled public class NacosDiscoveryAutoConfiguration {public NacosDiscoveryAutoConfiguration() {}BeanConditionalOnMissingBeanpublic NacosDiscoveryProperties nacosProperties() {return new NacosDiscoveryProperties();}BeanConditionalOnMissingBean // 需要传入NacosServiceManager 通过其进行服务发现public NacosServiceDiscovery nacosServiceDiscovery(NacosDiscoveryProperties discoveryProperties, NacosServiceManager nacosServiceManager) { return new NacosServiceDiscovery(discoveryProperties, nacosServiceManager);} } NacosServiceRegistryAutoConfiguration 上面两个一个是提供操作服务的Service一个是提供服务发现的功能那这个就是提供自动注册的功能其自动配置类如下 Configuration(proxyBeanMethods false ) EnableConfigurationProperties ConditionalOnNacosDiscoveryEnabled // 自定义Condition注解具体参考自动配置相关知识 ConditionalOnProperty(value {spring.cloud.service-registry.auto-registration.enabled},matchIfMissing true ) // 用于控制自动配置顺序 AutoConfigureAfter({AutoServiceRegistrationConfiguration.class, AutoServiceRegistrationAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class}) public class NacosServiceRegistryAutoConfiguration {public NacosServiceRegistryAutoConfiguration() {}Bean // 用于提供注册功能的Service其调用NacosServiceManager 进行实现 父类为 ServiceRegistryRpublic NacosServiceRegistry nacosServiceRegistry(NacosServiceManager nacosServiceManager, NacosDiscoveryProperties nacosDiscoveryProperties) {return new NacosServiceRegistry(nacosServiceManager, nacosDiscoveryProperties);}Bean // 承载服务注册所需的实例信息是注册数据的容器ConditionalOnBean({AutoServiceRegistrationProperties.class})public NacosRegistration nacosRegistration(ObjectProviderListNacosRegistrationCustomizer registrationCustomizers, NacosDiscoveryProperties nacosDiscoveryProperties, ApplicationContext context) {return new NacosRegistration((List)registrationCustomizers.getIfAvailable(), nacosDiscoveryProperties, context);}Bean // 自动服务注册的触发器监听事件并执行注册ConditionalOnBean({AutoServiceRegistrationProperties.class})public NacosAutoServiceRegistration nacosAutoServiceRegistration(NacosServiceRegistry registry, AutoServiceRegistrationProperties autoServiceRegistrationProperties, NacosRegistration registration) {return new NacosAutoServiceRegistration(registry, autoServiceRegistrationProperties, registration);} } 自动注册剖析 在上述第三个自动配置生效后会返回一个 new NacosAutoServiceRegistration(registry, autoServiceRegistrationProperties, registration); 分析其继承关系。 可以发现其关系图中有 ApplicationListener WebServerInitializedEvent 这个类其作用是会监听对应事件而这个事件就是WebServerInitializedEvent 代表嵌入式 Web 服务器已完成初始化并启动的通知机制。 public void onApplicationEvent(WebServerInitializedEvent event) {ApplicationContext context event.getApplicationContext();if (!(context instanceof ConfigurableWebServerApplicationContext) || !management.equals(((ConfigurableWebServerApplicationContext)context).getServerNamespace())) {this.port.compareAndSet(0, event.getWebServer().getPort());this.start(); // start方法}} 》 start 方法 public void start() {if (!this.isEnabled()) {if (logger.isDebugEnabled()) {logger.debug(Discovery Lifecycle disabled. Not starting);}} else {if (!this.running.get()) {this.context.publishEvent(new InstancePreRegisteredEvent(this, this.getRegistration()));this.registrationLifecycles.forEach((registrationLifecycle) - {registrationLifecycle.postProcessBeforeStartRegister(this.getRegistration());});this.register(); // 进行注册this.registrationLifecycles.forEach((registrationLifecycle) - {registrationLifecycle.postProcessAfterStartRegister(this.getRegistration());});if (this.shouldRegisterManagement()) {this.registrationManagementLifecycles.forEach((registrationManagementLifecycle) - {registrationManagementLifecycle.postProcessBeforeStartRegisterManagement(this.getManagementRegistration());});this.registerManagement();this.registrationManagementLifecycles.forEach((registrationManagementLifecycle) - {registrationManagementLifecycle.postProcessAfterStartRegisterManagement(this.getManagementRegistration());});}this.context.publishEvent(new InstanceRegisteredEvent(this, this.getConfiguration()));this.running.compareAndSet(false, true);}}}register方法 private final ServiceRegistryR serviceRegistry; ...... protected void register() {if (!this.registration.getNacosDiscoveryProperties().isRegisterEnabled()) {log.debug(Registration disabled.);} else {if (this.registration.getPort() 0) {this.registration.setPort(this.getPort().get());}super.register();}} // super.register() protected void register() {this.serviceRegistry.register(this.getRegistration()); // NacosRegistration}serviceRegistry.register public void register(Registration registration) {if (StringUtils.isEmpty(registration.getServiceId())) {log.warn(No service to register for nacos client...);} else {NamingService namingService this.namingService();String serviceId registration.getServiceId();String group this.nacosDiscoveryProperties.getGroup();Instance instance this.getNacosInstanceFromRegistration(registration);try {namingService.registerInstance(serviceId, group, instance); // 进行注册log.info(nacos registry, {} {} {}:{} register finished, new Object[]{group, serviceId, instance.getIp(), instance.getPort()});} catch (Exception var7) {Exception e var7;if (this.nacosDiscoveryProperties.isFailFast()) {log.error(nacos registry, {} register failed...{},, new Object[]{serviceId, registration.toString(), e});ReflectionUtils.rethrowRuntimeException(e);} else {log.warn(Failfast is false. {} register failed...{},, new Object[]{serviceId, registration.toString(), e});}}}}namingService.registerInstance public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {NamingUtils.checkInstanceIsLegal(instance);this.checkAndStripGroupNamePrefix(instance, groupName);this.clientProxy.registerService(serviceName, groupName, instance); // 通过代理去获取对应的注册服务}clientProxy.registerService public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {this.getExecuteClientProxy(instance).registerService(serviceName, groupName, instance);}getExecuteClientProxy private NamingClientProxy getExecuteClientProxy(Instance instance) {return (NamingClientProxy)(!instance.isEphemeral() !this.grpcClientProxy.isAbilitySupportedByServer(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC) ? this.httpClientProxy : this.grpcClientProxy);}是否临时服务判断 Nacos 提供两种注册方式一种是临时会进行心跳检测如果心跳检测不超过或者超时就会被任务不健康实例会对其进行下线其次会将其加入一个队列中去检测是否健康如果不健康那就移除。 一种是永久注册下面详细介绍 临时实例 (Ephemeral true) 生命周期特点 基于心跳维持客户端需要定期发送心跳包如果一定时间内未收到心跳Nacos会自动将实例标记为不健康并最终移除 适用场景 适合大多数微服务场景特别是云原生环境实例会随应用的启停自动注册和注销 数据存储 存储在内存中提供更高的性能在Nacos服务器重启时数据会丢失 持久化实例 (Ephemeral false) 生命周期特点 实例信息持久化到磁盘不依赖心跳维持即使客户端宕机实例也不会被自动移除 适用场景 适合那些需要保持稳定注册状态的场景如某些关键基础设施服务需要手动管理其上下线 数据存储 数据持久化到磁盘数据库中Nacos重启后数据仍然存在 HttpClient.registerService public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {LogUtils.NAMING_LOGGER.info([REGISTER-SERVICE] {} registering service {} with instance: {}, new Object[]{this.namespaceId, serviceName, instance});String groupedServiceName NamingUtils.getGroupedName(serviceName, groupName);if (instance.isEphemeral()) {throw new UnsupportedOperationException(Do not support register ephemeral instances by HTTP, please use gRPC replaced.);} else {MapString, String params new HashMap(32);params.put(namespaceId, this.namespaceId);params.put(serviceName, groupedServiceName);params.put(groupName, groupName);params.put(clusterName, instance.getClusterName());params.put(ip, instance.getIp());params.put(port, String.valueOf(instance.getPort()));params.put(weight, String.valueOf(instance.getWeight()));params.put(enable, String.valueOf(instance.isEnabled()));params.put(healthy, String.valueOf(instance.isHealthy()));params.put(ephemeral, String.valueOf(instance.isEphemeral()));params.put(metadata, JacksonUtils.toJson(instance.getMetadata()));this.reqApi(UtilAndComs.nacosUrlInstance, params, POST);}}Grpc.registerService public void registerService(String serviceName, String groupName, Instance instance) throws NacosException {LogUtils.NAMING_LOGGER.info([REGISTER-SERVICE] {} registering service {} with instance {}, new Object[]{this.namespaceId, serviceName, instance});if (instance.isEphemeral()) {this.registerServiceForEphemeral(serviceName, groupName, instance);} else {this.doRegisterServiceForPersistent(serviceName, groupName, instance);}}自上自动注册服务就到此为止
http://www.pierceye.com/news/372951/

相关文章:

  • 网站设计文献网站开发与维护岗位说明书
  • 公司制作网站东莞南城房价
  • 智能建站系统seo网站优化方案
  • 南宁网站建设找建站通成都seo推广
  • 网站做镜像的有什么用建设银行流水网站
  • 湖北网站定制开发价格表宣传片制作协议
  • 开网站要多少钱自己怎样做网站
  • 建设网站的教程免费的wordpress分类在哪设置
  • 电子书网站 跟我学做家常菜800网站建设与维护 教学大纲
  • 河南省住房城乡建设主管部门网站wordpress还有人在用吗
  • 好口碑关键词优化沈阳企业关键词优化
  • 外汇自动跟单网站开发wordpress支持中文
  • 南宁网站建设推广教育类网站框架
  • 定制网站建设服务公司摄影设计师招聘
  • 地图 添加到网站观点网站
  • 给分管领导网站建设情况汇报怎么写企业网站的发展历史
  • 佛山营销网站建设费用app制作器下载软件
  • 如何将优酷视频上传到自己网站万能网
  • 域名销售网站wordpress 数据库配置文件
  • 广州营销型网站建设怎么样做网站必须要认证吗
  • 网站开发主要内容免费商城平台
  • 青岛建站方案海兴县网站建设公司
  • 网站文案框架兰州网页制作公司网站
  • 专业网站有哪些平台wordpress那个版本
  • 网站建设按钮详情页设计图
  • 杭州公司注册代理中介深圳关键词优化软件
  • 乐清网站制作公司电话免费做初中试卷的网站
  • 注册一个网站的流程反向代理服务器做wordpress外网
  • 沁阳网站建设tomcat建网站
  • 品牌网站建设公司推荐网站建设公司3lue