- springCloud学习记录
- Bus(消息总线)
- 服务端
- pom
- yml
- 启动类
- 客户端
- pom
- yml
- 启动类
- 方法类获取配置信息
在SpringCloud config的基础上实现多台服务器修改,需要用到rabbitmq,git上的配置信息存到rabbitmq里面,git更新后更新到rabbitmq,客户端从rabbitmq里面取
服务端 pomymlorg.springframework.cloud spring-cloud-starter-bus-amqp
server: port: 3344 spring: application: name: cloud-config-center cloud: # 服务地址相关配置 config: server: git: uri: git@github.com:leelovejava/springcloud-config.git search-paths: - spring-config label: master eureka: client: service-url: defaultZone: http://eureka7001.com:7001/eureka启动类
@SpringBootApplication @EnableConfigServer // 配置中心服务 public class ConfigCenterMain3344 { public static void main(String[] args) { SpringApplication.run(ConfigCenterMain3344.class, args); } }客户端 pom
ymlorg.springframework.cloud spring-cloud-starter-bus-amqp
server: port: 3355 spring: application: name: config-client cloud: config: label: master # 分支名称 name: config #配置文件名称 profile: dev # 读取的后缀,上述三个综合,为master分支上的config-dev.yml的配置文件被读取,http://config-3344.com:3344/master/config-dev.yml uri: http://config-3344.com:3344 #配置中心的地址 rabbitmq: #rabbitmq相关配置,15672是web管理端口,5672是mq访问端口 port: 5672 host: localhost username: guest password: guest eureka: client: service-url: defaultZone: http://eureka7001.com:7001/eureka management: endpoints: web: exposure: include: "*"启动类
@SpringBootApplication @EnableEurekaClient public class ConfigClientMain3355 { public static void main(String[] args) { SpringApplication.run(ConfigClientMain3355.class, args); } }方法类获取配置信息
@RestController @RefreshScope public class ConfigClientController { @Value("${config.info}") private String configInfo; @GetMapping("/configInfo") public String getConfigInfo(){ return configInfo; } }
全局通知修改:curl -X POST “http:/localhost:3344/actuator/bus-refresh”
指定服务修改:curl -X POST “http:/localhost:3344/actuator/bus-refresh/config-client:3355”
config-client:服务名称
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)