<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      config-server-bus動態更新配置

      config-server用來搭建配置中心,而配置信息一般使用gitlab倉庫來存儲,這樣在你的配置發生改變時,不需要從新打包,而如果使用native的試,則需要從新打一個config-server的jar包。

      配置的熱更新

      當你的服務的配置信息發生改變時,一般來說需要從新重啟你的服務,配置信息才能生效,這對于我們來說是不友好的,所以springcloud有一種消息總線的方式來實現配置信息的熱更新,更你的服務不需要從新啟動。

      項目搭建

      eureka-server

      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
      </dependency>
      

      程序添加注解

      @SpringBootApplication
      @EnableEurekaServer
      public class EurekaserverApplication {
      
        public static void main(String[] args) {
          SpringApplication.run(EurekaserverApplication.class, args);
        }
      
      }
      

      yml文件

      server:
       port: 8761
      
      eureka:
       instance:
         hostname: localhost
       client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
          defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
        server:
         enable-self-preservation: false #自我保護機制
         eviction-interval-timer-in-ms: 30000  #及時踢出已關停的節點
      

      config-server

      它是配置中心,其它服務如果通過config-server在eureka里的服務名去連接它,這種是以eureka為核心;也可以單獨指定,并把eureka的信息寫到config-server倉庫里,這是以config-server為核心,這兩種方式都可以,咱們這個例子是以eureka為核心的,所以config-server也是一個eureka-client.

      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-config-server</artifactId>
      </dependency>
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      </dependency>
      

      程序添加注解

      @SpringBootApplication
      @EnableDiscoveryClient
      @EnableConfigServer
      public class ConfigserverApplication {
      
        public static void main(String[] args) {
          SpringApplication.run(ConfigserverApplication.class, args);
        }
      
      }
      
      

      添加yml配置

      spring:
        application:
          name: config-server
        cloud:
          config:
            server:
              git:
                uri: git@github.com:***/config_repo.git
                username: ***
                password: ***
                searchPaths: '{profile}'
      server:
        port: 8888
      eureka:
        client:
          service-url:
            defaultZone: http://localhost:8761/eureka/
      

      config-client-service1

      這是我們具體的業務服務,它是一個eureka-client也是一個config-client,它需要把自己注冊到eureka里,也需要從config-server拉自己的信息,它需要有配置信息的熱更新,所以這需要引用amqp包和actuator健康檢測包。

      <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
              </dependency>
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-web</artifactId>
              </dependency>
      
              <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-config</artifactId>
              </dependency>
              <dependency>
                  <groupId>org.springframework.cloud</groupId>
                  <artifactId>spring-cloud-starter-bus-amqp</artifactId>
              </dependency>
              <dependency>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-starter-actuator</artifactId>
              </dependency>
      

      程序添加注解

      @SpringBootApplication
      @EnableDiscoveryClient
      @RestController
      @RefreshScope
      public class Service1Application {
      
        @Value("${auth.name:empty}")
        String author;
      
        public static void main(String[] args) {
          SpringApplication.run(Service1Application.class, args);
        }
      
        @GetMapping("/hello")
        public String hello() {
          return author;
        }
      }
      

      添加yml文件

      spring:
        cloud:
          bus.trace.enabled: true #配置動態更新
          rabbitmq:
            host: 127.0.0.1
            port: 5672
            username: guest
            password: guest
          config:
            discovery:
              enabled: true #這塊表示啟用service-id不用uri
              service-id: config-server  #這塊是服務的id
            label: master
            profile: svt
        application:
          name: service1
      server:
        port: 8081
      eureka:
        instance:
          prefer-ip-address: true #基于IP地址的注冊而不是主機名
        client:
          service-url:
            defaultZone: http://localhost:8761/eureka
      logging:
        level:
          org:
            springframework:
              security: DEBUG
      management:
        endpoints:
          web:
            exposure:
              include: bus-refresh
      
      

      配置更新

      當你的config_repo倉庫有文件更新時,你可以調用任意一個服務去觸發它,測試的代碼如

       curl -v -X POST "http://localhost:8081/actuator/bus-refresh"
      

      如果成功后,一般會返回httpstatuscode:204的狀態碼,當然這種也是手動更新,如果希望動態更新,可以在gitlab或者github上對config_repo項目添加webhook的事件,當有分支合并到dev或者master時,去自動觸發bus-refresh。

      posted @ 2019-12-05 13:27  張占嶺  閱讀(1556)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产一区二区av天堂热| 国产精品视频亚洲二区| 蜜芽久久人人超碰爱香蕉| 老熟妇乱子交视频一区| 欧美 亚洲 另类 丝袜 自拍 动漫 久久久久久久久毛片精品 | 国产精品点击进入在线影院高清 | 国产一区精品综亚洲av| 国产精品一区在线蜜臀| 中文字幕无码视频手机免费看| 少妇人妻偷人精品视蜜桃| 久久精品女人的天堂av| 少妇真人直播免费视频| 久久人人97超碰精品| 日韩 一区二区在线观看| 亚洲国产韩国欧美在线| 无码国内精品人妻少妇| 精品无码久久久久久尤物| 东乡县| 激情综合网激情五月俺也想 | 元氏县| 欧美日产国产精品日产| 色婷婷久久综合中文久久一本| 久久亚洲精品无码播放| 国产精品自拍自在线播放| Y111111国产精品久久久| 极品无码国模国产在线观看| 高清自拍亚洲精品二区 | 青青草无码免费一二三区| 色偷偷成人综合亚洲精品| 亚洲一区二区三区在线| 亚洲综合av一区二区三区| 成在线人视频免费视频| 爱性久久久久久久久| 国99久9在线 | 免费| 18禁国产一区二区三区| 精品国产成人午夜福利| 高清无码爆乳潮喷在线观看| 国产精品午夜福利合集| 最新中文字幕国产精品| 久久伊99综合婷婷久久伊| 色欲国产精品一区成人精品|