SpringCloud之配置中心Config-创新互联

commons 工程
commons 工程 - POM 文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.zwc
springcloud-config-git-commons
1.0

springcloud-config-git-commons
ZFX代理申请www.fx61.com/brokerlist/zfx.html公用工程

jar



UTF-8

1.8

Cairo-SR3

Finchley.RELEASE












io.spring.platform
platform-bom
${platform-bom.version}
pom
import



org.springframework.cloud
spring-cloud-dependencies
${spring-cloud-dependencies.version}
pom
import


网站的建设成都创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为成都石雕等企业提供专业服务。


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    


配置一些共用依赖
commons 工程 - 项目结构
配置文件
  创建一个 Git 库,里面存放配置文件,文件夹名称为:config-repo;这里模拟不同的环境,所以分别构建了
  dev(开发)、uat(测试)以及 online(线上)三种不同的配置文件;此文件夹存在此项目的根目录中

  • springcloud-config-git
      - config-repo
        - system-dev.properties
        - system-online.properties
        - system-uat.properties
    • springcloud-config-git-commons
    • springcloud-config-git-service
      service 工程
        ① 此工程下有两个模块:一个 server,一个 client
      server(获取远程的配置信息)
      server - POM 文件

      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      4.0.0


      com.zwc
      springcloud-config-git-service
      1.0


      com.zwc
      springcloud-config-git-server-service
      1.0

      springcloud-config-git-server-service
      config server

      jar







      com.zwc
      springcloud-config-git-commons
      1.0



      org.springframework.cloud
      spring-cloud-config-server






      org.springframework.boot
      spring-boot-maven-plugin




      主要加入 spring-cloud-config-server 依赖
      server - application.yml 配置文件
      端口
      server:
      port: 8000
      spring:
      application:
      应用名称
      name: config-git-server
      cloud:
      config:
      server:
      git:
      仓库地址
      对应 {label} 部分,即 Git 的分支
      label: master
      仓库文件夹名称,多个以逗号分隔
      search-paths: springcloud-config-git/config-repo
      git 仓库用户名(公开库可以不用填写)
      username:
      git 仓库密码(公开库可以不用填写)
      password:
      注意这里 uri 只能写到仓库名
      如果配置文件在仓库中多层目录下,那么 search-paths 就从根目录开始写起
      server - 启动类
      package com.zwc;
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication
      br/>@SpringBootApplication
      public class SpringcloudConfigGitServerServiceApplication {
      public static void main(String[] args) {
      SpringApplication.run(SpringcloudConfigGitServerServiceApplication.class, args);
      }

}
添加 @EnableConfigServer 注解表示开启配置中心
实现原理
1、ConfigServer(配置中心服务端)从远端git拉取配置文件并在本地git一份,ConfigClient(微服务)从ConfigServer端获取自己对应 配置文件;
2、当远端git仓库配置文件发生改变,ConfigServer如何通知到ConfigClient端,即ConfigClient如何感知到配置发生更新?
Spring Cloud Bus会向外提供一个http接口,即图中的/bus/refresh。我们将这个接口配置到远程的git的webhook上,当git上的文件内容发生变动时,就会自动调用/bus-refresh接口。Bus就会通知config-server,config-server会发布更新消息到消息总线的消息队列中,其他服务订阅到该消息就会信息刷新,从而实现整个微服务进行自动刷新。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:SpringCloud之配置中心Config-创新互联
当前网址:http://lszwz.com/article/eiecc.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款