Spring Cloud Bus做配置更新步驟如下:
1.提交代碼觸發(fā)post給Server端發(fā)送bus/refresh
2.Server端接收到請求并發(fā)送給Spring Cloud Bus
3.Spring Cloud bus接到消息并通知給其它客戶端
4.其它客戶端接收到通知箭阶,請求Server端獲取最新配置
5.全部客戶端均獲取到最新的配置
在server端的代碼做一些改動,來支持/actuator/bus-refresh
(1)添加依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
(2)application.yml
server:
port: 8097
spring:
application:
name: spring-cloud-config-server
cloud:
config:
server:
git:
uri: https://github.com/xxx/springcloud-config # git倉庫的地址
# search-paths: # 倉庫文件夾名稱,多個以逗號分隔
username: #Git倉庫用戶名
password: #Git倉庫密碼
default-label: main
rabbitmq:
host: 127.0.0.1
port: 5672
username:
password:
management:
endpoints:
web:
exposure:
include: "*"
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
依次啟動eureka仇参,config-serve嘹叫,config-client1,config-client2诈乒,修改git上的配置罩扇,訪問curl -X POST http://localhost:8081/actuator/bus-refresh,可以看到兩個客戶端都能拿到修改后的值