javascript
SpringCloud教程-消息总线Bus 服务端(server)刷新(SpringCloud版本Greenwich.SR4)
文章目錄
- 項(xiàng)目示例
- config-server-bug
代碼地址:github-spring-cloud地址
前言:本篇文章在上一篇文章基礎(chǔ)上進(jìn)行修改,因?yàn)殡m然我們做到了利用一個(gè)消息總線觸發(fā)刷新,而刷新所有客戶端配置的目的,但是這種方式并不合適。原因有兩點(diǎn):
1、破壞了微服務(wù)各節(jié)點(diǎn)的對(duì)等性,2、如果客戶端ip有變化,這時(shí)我們就需要修改WebHook的配置。
上篇文章的架構(gòu)模式稍微改變一下(圖片來(lái)源網(wǎng)絡(luò))
這時(shí)Spring Cloud Bus做配置更新步驟如下:
項(xiàng)目示例
config-server-bug
pom文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>spring-cloud-learn</artifactId><groupId>com.sl.learn.cloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><groupId>com.sl.learn.cloud</groupId><artifactId>config-server-bus</artifactId><version>1.0-SNAPSHOT</version><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</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-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-hystrix --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency></dependencies></project>配文文件application.properties
spring.application.name=config-server-bus server.port=8088 eureka.client.serviceUrl.defaultZone=http://localhost:8080/eureka/ spring.cloud.config.server.git.uri=https://github.com/FadeHub/SpringCloudConfig spring.cloud.config.server.git.searchPaths=repo spring.cloud.config.label=master spring.cloud.config.username= spring.cloud.config.password=management.endpoints.web.exposure.include= * management.endpoint.health.show-details= always management.endpoint.shutdown.enabled= true info.app.name = spring-boot-actuator info.app.version = 1.0.0 info.app.test = test## 開(kāi)啟消息跟蹤 spring.cloud.bus.trace.enabled=truespring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest啟動(dòng)類Application
@SpringBootApplication @RestController @RefreshScope @EnableEurekaClient @EnableConfigServer @EnableDiscoveryClient public class ConfigServerBusApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerBusApplication.class,args);}}依次啟動(dòng)eureka,config-serve-bus,config-client。
按照上篇的測(cè)試方式,訪問(wèn)客戶端測(cè)試均可以正確返回信息。同樣修改配置文件,將值改為:hello config server bus update并提交到倉(cāng)庫(kù)中。在win10下使用下面命令來(lái)模擬webhook。
curl -v -X POST http://localhost:8088/actuator/refresh
執(zhí)行完成后,訪問(wèn)客戶端,返回:hello config server bus update
總結(jié)
以上是生活随笔為你收集整理的SpringCloud教程-消息总线Bus 服务端(server)刷新(SpringCloud版本Greenwich.SR4)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: SpringCloud教程-消息总线Bu
- 下一篇: SpringCloud教程- 服务链路追