1. 程式人生 > >SrpingCloud 之SrpingCloud config分散式配置中心實時重新整理

SrpingCloud 之SrpingCloud config分散式配置中心實時重新整理

預設情況下是不能及時獲取變更的配置檔案資訊

Spring Cloud分散式配置中心可以採用手動或者自動重新整理

 1、手動需要人工呼叫介面   監控中心

 2、訊息匯流排實時通知  springbus

 

動態重新整理資料

在SpringCloud中有手動重新整理配置檔案和實時重新整理配置檔案兩種方式。

手動方式採用actuator端點重新整理資料

實時重新整理採用SpringCloud Bus訊息匯流排

 

 

  

actuator端點重新整理資料

在config clientr引入 

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency>

  

yml中開啟監控斷點

management:
  endpoints:
    web:
      exposure:
        include: "*"

 同時在controller加 @RefreshScope 

package com.toov5.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class TestController { @Value("${motto}") //配置的key private String motto; @RequestMapping("/getMotto") public String getMotto() { return motto; } }

 

開啟: 修改git上的配置檔案資訊

必須要用post請求!

http://127.0.0.1:8882/actuator/refresh

 

成功!

 每個客戶端都有監聽,效果不是很好這樣的方式。手動重新整理比較好一些。改完了自己手動重新整理下 post 呼叫一下