cloud bus刷新
1.大概代码
cloud-config-center3344是cloud config server端,cloud-config-client3355 和 cloud-config-client3366 是cloud config client端.
修改以下配置,
cloud-config-center3344:
pom:
<!--添加消息总线rabbitmq支持--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
yml:
spring: application: name: cloud-config cloud: config: server: git: uri: https://github.com/lulu4pix/springcloud-config.git search-paths: - springcloud-config force-pull: true username: 914104723@qq.com password: Aa123567. label: master #rabbitmq相关配置 rabbitmq: host: localhost port: 5672 username: guest password: guest #rabbitmq相关配置,暴露bus刷新配置端点 management: endpoints: #暴露bus配置的端点 web: exposure: include: 'bus-refresh'
cloud-config-client3355 和 cloud-config-client3366:
pom:
<!--添加消息总线rabbitmq支持--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
yml:
server: port: 3355 spring: application: name: cloud-config-client cloud: config: label: master #分支 name: application profile: dev #这三个的意思是从master分支上,读取application-dev.yml文件内容 uri: http://localhost:3344/ #配置中心地址 #rabbitmq相关配置 rabbitmq: host: localhost port: 5672 username: guest password: guest eureka: client: service-url: defaultZone: http://localhost:7001/eureka/ #单机版 #之所以颜色淡是因为在cloud config 手动刷新已经添加过了。 management: endpoints: web: exposure: include: "*"
测试:
修改github上的application-dev.yml内容从version8改成9
访问http://localhost:3344/master/application-dev.yml 已经更新
post请求发送3344的bus-refresh: curl -X POST http://localhost:3344/actuator/bus-refresh
再访问3355和3366:
都自动更新成功。
具体的代码见:
https://github.com/lulu4pix/springcloud/commit/a50f2948d217650160cb9c5a83fc2e9f546de617