spring cloud config和bus組件實(shí)現(xiàn)自動(dòng)刷新功能
1.啟動(dòng)RabbitMQ
2.修改config服務(wù)端 依賴:(boot和cloud版本不要太高,不然刷新配置的請(qǐng)求不能用)
<dependencies> <!--consul--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> </dependency> <!--健康檢查--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--config--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <!--bus--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> <!--web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
配置:
spring: cloud: consul: host: localhost port: 8500 config: server: git: uri: https://gitee.com/xiang_pei/config.git default-label: master application: name: CONFIGSERVER rabbitmq: host: localhost port: 5672 username: guest password: guest virtual-host: / #暴露所有端點(diǎn),便于發(fā)送更新配置請(qǐng)求 management: endpoints: web: exposure: include: "*"
啟動(dòng):(啟動(dòng)類加@EnableConfigServer)mq會(huì)有一條臨時(shí)隊(duì)列
3.修改微服務(wù)(即客戶端) 依賴:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-consul-discovery</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!--config client的依賴--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <!--重新導(dǎo)入bootstrap--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> <!--bus--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> </dependencies>
配置:不變(rabbitmq的配置應(yīng)該寫到gitee上)bootstrap.properties
spring.cloud.consul.host=localhost spring.cloud.consul.port=8500 spring.application.name=CONFIGCLIENT spring.cloud.config.discovery.service-id=CONFIGSERVER spring.cloud.config.discovery.enabled=true spring.cloud.config.name=config spring.cloud.config.label=master spring.cloud.config.profile=dev
運(yùn)行:
寫了一個(gè)測(cè)試方法
name屬性是gitee上的配置文件的name
沒問(wèn)題
4.利用webhooks實(shí)現(xiàn)自動(dòng)刷新配置
向config服務(wù)端發(fā)送post請(qǐng)求
http://localhost:8080/actuator/bus-refresh
具體路徑根據(jù)項(xiàng)目來(lái)
在gitee的config管理中,點(diǎn)擊webhooks
url就填上面那個(gè),因?yàn)樾枰W(wǎng)才能測(cè)試,所以暫時(shí)不演示了。
設(shè)置完,改gitee的配置就會(huì)自動(dòng)刷新了
到此這篇關(guān)于spring cloud config和bus組件實(shí)現(xiàn)自動(dòng)刷新功能的文章就介紹到這了,更多相關(guān)spring cloud config自動(dòng)刷新內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JAVA中的deflate壓縮實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇JAVA中的deflate壓縮實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09Java(基于Struts2) 分頁(yè)實(shí)現(xiàn)代碼
這篇文章介紹了Java(基于Struts2) 分頁(yè)實(shí)現(xiàn)代碼,有需要的朋友可以參考一下2013-10-10Java的JSON轉(zhuǎn)換庫(kù)GSON的基本使用方法示例
GSON是Google制作的一個(gè)可以讓Java對(duì)象與JSON互相轉(zhuǎn)換的類庫(kù),下面我們就來(lái)看一下Java的JSON轉(zhuǎn)換庫(kù)GSON的基本使用方法示例:2016-06-06Mybatis-Plus支持GBase8s分頁(yè)查詢的實(shí)現(xiàn)示例
本文主要介紹了使?Mybatis-Plus?支持?GBase8s?的分頁(yè)查詢,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01Java字符串拼接的五種方法及性能比較分析(從執(zhí)行100次到90萬(wàn)次)
字符串拼接一般使用“+”,但是“+”不能滿足大批量數(shù)據(jù)的處理,Java中有以下五種方法處理字符串拼接及性能比較分析,感興趣的可以了解一下2021-12-12SpringBoot中使用Redis?Stream實(shí)現(xiàn)消息監(jiān)聽示例
本文主要介紹了SpringBoot中使用Redis?Stream實(shí)現(xiàn)消息監(jiān)聽示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06