當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringCloud教程-消息总线Bus 服务端(server)刷新(SpringCloud版本Greenwich.SR4)
生活随笔
收集整理的這篇文章主要介紹了
SpringCloud教程-消息总线Bus 服务端(server)刷新(SpringCloud版本Greenwich.SR4)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 項目示例
- config-server-bug
代碼地址:github-spring-cloud地址
前言:本篇文章在上一篇文章基礎上進行修改,因為雖然我們做到了利用一個消息總線觸發刷新,而刷新所有客戶端配置的目的,但是這種方式并不合適。原因有兩點:
1、破壞了微服務各節點的對等性,2、如果客戶端ip有變化,這時我們就需要修改WebHook的配置。
上篇文章的架構模式稍微改變一下(圖片來源網絡)
這時Spring Cloud Bus做配置更新步驟如下:
項目示例
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## 開啟消息跟蹤 spring.cloud.bus.trace.enabled=truespring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest啟動類Application
@SpringBootApplication @RestController @RefreshScope @EnableEurekaClient @EnableConfigServer @EnableDiscoveryClient public class ConfigServerBusApplication {public static void main(String[] args) {SpringApplication.run(ConfigServerBusApplication.class,args);}}依次啟動eureka,config-serve-bus,config-client。
按照上篇的測試方式,訪問客戶端測試均可以正確返回信息。同樣修改配置文件,將值改為:hello config server bus update并提交到倉庫中。在win10下使用下面命令來模擬webhook。
curl -v -X POST http://localhost:8088/actuator/refresh
執行完成后,訪問客戶端,返回:hello config server bus update
總結
以上是生活随笔為你收集整理的SpringCloud教程-消息总线Bus 服务端(server)刷新(SpringCloud版本Greenwich.SR4)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringCloud教程-消息总线Bu
- 下一篇: SpringCloud教程- 服务链路追