xxw1754352621 / java-dev

愿景:提升自我知识容量,扩展自我知识边界
Apache License 2.0
6 stars 2 forks source link

spring boot 结合 consul 实现配置,自动更新 #1

Closed xxw1754352621 closed 5 years ago

xxw1754352621 commented 5 years ago

1.Spring Boot Actuator Starter的使用 Starter for using Spring Boot's Actuator which provides production-ready features to help you monitor and manage your application

2.spring consul的使用

org.springframework.cloud spring-cloud-consul-config
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-consul-discovery</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-netflix-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-ribbon</artifactId>
    </dependency>

3.关键实现类,spring-cloud-consul-config下的ConfigWatch

@Scheduled(fixedDelayString = "${spring.cloud.consul.config.watch.delay:1000}")

xxw1754352621 commented 5 years ago

Config Watch 固定延时获取配置 https://cloud.spring.io/spring-cloud-consul/spring-cloud-consul.html#spring-cloud-consul-config-watch

xxw1754352621 commented 5 years ago

解决方法如下:

https://github.com/xxw1754352621/java-dev/blob/master/spring%E4%BD%93%E7%B3%BB/spring%20boot/spring%20boot%20consul%E8%AF%BB%E5%8F%96%E5%92%8C%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0.md

xxw1754352621 commented 4 years ago

1.请求参数设置 http://xxx/v1/kv/pds/pds-asm/?recurse&wait=55s&index=801516等 2.响应结果的index缓存和比较 org.springframework.cloud.consul.config.ConfigWatch#consulIndexes来自于 项目启动创建的org.springframework.cloud.consul.config.ConsulPropertySourceLocator#contextIndex