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

商务科技网站建设自建商城网站有哪些平台

商务科技网站建设,自建商城网站有哪些平台,深圳网站建设icxun,wordpress network系列文章目录 Springboot源码分析之apollo配置 文章目录 系列文章目录前言一、apollo是如何完成初始化的,拉取配置的呢1. apollo的初始化阶段2.初始化RemoteConfigRepository3.同步远程配置4.发布ConfigFileChangeEvent事件 总结 前言 配置中心我相信有一年开发经验的程序员都…系列文章目录 Springboot源码分析之apollo配置 文章目录 系列文章目录前言一、apollo是如何完成初始化的,拉取配置的呢1. apollo的初始化阶段2.初始化RemoteConfigRepository3.同步远程配置4.发布ConfigFileChangeEvent事件 总结 前言 配置中心我相信有一年开发经验的程序员都听过吧有三年开发经验的程序100%都使用过配置中心配置吧。apollo做为常用的配置中心你知道它的原理吗你知道它是怎么集成到springboot的吗 本篇文章带你了解其原理让你也能够自定义组件。 一、apollo是如何完成初始化的,拉取配置的呢 1. apollo的初始化阶段 Springboot环境准备阶段发布ApplicationEnvironmentPreparedEvent 事件EnvironmentPostProcessorApplicationListener 监听到事件之后 执行 postProcessEnvironment方法。apollo 中 的初始化类 ApolloApplicationContextInitializer 就实现EnvironmentPostProcessor接口。 ApolloApplicationContextInitializer public void postProcessEnvironment(ConfigurableEnvironment configurableEnvironment, SpringApplication springApplication) {// should always initialize system properties like app.id in the first placeinitializeSystemProperty(configurableEnvironment);Boolean eagerLoadEnabled configurableEnvironment.getProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_EAGER_LOAD_ENABLED, Boolean.class, false);//EnvironmentPostProcessor should not be triggered if you dont want Apollo Loading before Logging System Initializationif (!eagerLoadEnabled) {return;}Boolean bootstrapEnabled configurableEnvironment.getProperty(PropertySourcesConstants.APOLLO_BOOTSTRAP_ENABLED, Boolean.class, false);if (bootstrapEnabled) {DeferredLogger.enable();//重点实现逻辑的方法initialize(configurableEnvironment);}}2.初始化RemoteConfigRepository 经过initialize()方法层层调用最后进入到RemoteConfigRepository init public RemoteConfigRepository(String namespace) {m_namespace namespace;m_configCache new AtomicReference();m_configUtil ApolloInjector.getInstance(ConfigUtil.class);m_httpClient ApolloInjector.getInstance(HttpClient.class);m_serviceLocator ApolloInjector.getInstance(ConfigServiceLocator.class);remoteConfigLongPollService ApolloInjector.getInstance(RemoteConfigLongPollService.class);m_longPollServiceDto new AtomicReference();m_remoteMessages new AtomicReference();m_loadConfigRateLimiter RateLimiter.create(m_configUtil.getLoadConfigQPS());m_configNeedForceRefresh new AtomicBoolean(true);m_loadConfigFailSchedulePolicy new ExponentialSchedulePolicy(m_configUtil.getOnErrorRetryInterval(),m_configUtil.getOnErrorRetryInterval() * 8);//下面三个方法就是拉去配置的核心代码了 //同步远程配置 this.trySync();//固定频率刷新、内部实现也是调用trySync()this.schedulePeriodicRefresh();//轮询访问远程配置中心每次访问直到超时或者apollo 配置发生变化this.scheduleLongPollingRefresh();}3.同步远程配置 AbstractConfigRepository.trySync()同步远程配置方法方法内部主要实现逻辑在sync()中 protected synchronized void sync() {Transaction transaction Tracer.newTransaction(Apollo.ConfigService, syncRemoteConfig);try {//m_configCache ApolloConfig previous m_configCache.get();//加载 远程 apollo configApolloConfig current loadApolloConfig();//reference equals means HTTP 304if (previous ! current) {logger.debug(Remote Config refreshed!);m_configCache.set(current);//getConfig 方法 将apollo配置放进 properties中this.fireRepositoryChange(m_namespace, this.getConfig());}if (current ! null) {Tracer.logEvent(String.format(Apollo.Client.Configs.%s, current.getNamespaceName()),current.getReleaseKey());}transaction.setStatus(Transaction.SUCCESS);} catch (Throwable ex) {transaction.setStatus(ex);throw ex;} finally {transaction.complete();}}private volatile AtomicReferenceApolloConfig m_configCache; 使用了volatile 修饰原子引用类型进行封装引用这就是看源码的意义吧 4.发布ConfigFileChangeEvent事件 sync() 方法中的 调用fireRepositoryChange(),最后会调用到AbstractConfigFile.fireConfigChange()方法 private void fireConfigChange(final ConfigFileChangeEvent changeEvent) {for (final ConfigFileChangeListener listener : m_listeners) {m_executorService.submit(new Runnable() {Overridepublic void run() {String listenerName listener.getClass().getName();Transaction transaction Tracer.newTransaction(Apollo.ConfigFileChangeListener, listenerName);try {//listner 是一个PropertySourcesProcessor 中的一个lambda 类//ConfigChangeListener configChangeEventPublisher changeEvent -//applicationEventPublisher.publishEvent(new ApolloConfigChangeEvent(changeEvent));listener.onChange(changeEvent);transaction.setStatus(Transaction.SUCCESS);} catch (Throwable ex) {transaction.setStatus(ex);Tracer.logError(ex);logger.error(Failed to invoke config file change listener {}, listenerName, ex);} finally {transaction.complete();}}});}}因此我们可以监听ApolloConfigChangeEvent事件来监听apollo配置是否发生产变化 eg public class ListenerApollo implements ConfigChangeListener, ApplicationListenerApolloConfigChangeEvent {Overridepublic void onChange(ConfigChangeEvent configChangeEvent) {//核心线程配置发生变化、重新setConfigChange coreSize configChangeEvent.getChange(threadPool.corePoolSize);if( coreSize! null){ThreadPoolExecutor executor SpringUtil.getBean(ThreadPoolExecutor.class);executor.setCorePoolSize(Integer.valueOf(coreSize.getNewValue()));}}Overridepublic void onApplicationEvent(ApolloConfigChangeEvent event) {this.onChange(event.getConfigChangeEvent());} }总结 分析apollo在Springboot启动的哪个环节被集成初始化的以及跟了同步远程配置的逻辑初始化时同步一次定时同步长轮询监听配置是否发生变化发生变化又通知程序进行同步。并且同步后也会发布一个ApolloConfigChangeEvent事件,放开发者去监听配置变化。
http://www.zqtcl.cn/news/290495/

相关文章:

  • 注册网站引流wordpress5.0.2图集怎么发布
  • 360产品展示网站哈尔滨个人建站模板
  • 怎么做网站的浏览量陕西省住房和建设厅官方网站
  • 上海网站 备案查询平面设计接单网站有哪些
  • 用别人的公司名字做网站想自己做网站推广
  • 百度智能建站平台建设工程信息网官网入口查询
  • 比价网站源码整站程序服务器怎么发布网站
  • html插件代码大全济南网站关键词优化公司
  • 优秀的手机网站设计网站推广的特点
  • 滨州北京网站建设电子商务网站规划与管理
  • 如何注册公司网站域名中国有几大网站
  • php网站留言板怎么做wordpress 相关文章推荐
  • 怎么看网站被惩罚专业的网站建设流程
  • 如何制作手机免费网站模板下载用户体验设计师是什么
  • php网站建设基本流程基于php网站开发设计
  • 建设一个网站需要哪些软硬件条件无做弊的棋牌游戏网站
  • 最有设计感的网站扬中网站建设 优帮云
  • 企业建设银行网站登录不了wordpress需要ftp
  • 广州营销型网站建设团队专业建设内涵包括哪些内容
  • 网站如何做响应式布局外国网站上做Task
  • 知乎网站建设入门书大渡口集团网站建设
  • 免费网站建设是什么宁波网站建设的价格表
  • 网站设计导航栏高度网站设计的经营范围
  • 帮别人建设网站多少利润北京网站建设公司华网制作作
  • 微信网站需要备案吗瑞安商业网站建设
  • 做网站如何计算工资wordpress stheme
  • 网站建设销售人才简历wordpress 搜索tag
  • 设计网站专业云南旅行社网站开发
  • 小规模开普票网站建设几个点张浦专业做网站
  • 点击图片跳转到网站怎么做链接网址后缀名大全