2019-08-27/spring cloud bus 自动刷新配置

以spring cloud Greenwich.SR2和spring boot 2.1.5.RELEASE 版本举例。假设本地已经安装了RabitMQ。
config server的pom:

     
            org.springframework.cloud
            spring-cloud-config-server
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            org.springframework.cloud
            spring-cloud-starter-bus-amqp
        

congfig server的application.yml:

server:
  port: 8888

eureka:
  client:
    service-url:
      # 将自己注册到eureka server的地址
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: config
  cloud:
    config:
      server:
        git:
          uri: https://github.com/fantasyWJP/wxdc_config_study_original.git
          username: xxx
          password: xxx
    bus:
      refresh:
        enabled: true

management:
  endpoints:
    web:
      exposure:
        include: bus-refresh

其余节点的pom:

         
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        

        
            org.springframework.cloud
            spring-cloud-config-client
        

        
            org.springframework.cloud
            spring-cloud-starter-bus-amqp
        

其余节点的bootstrap.yml配置:

server:
  port: 8763

eureka:
  client:
    service-url:
      # 将自己注册到eureka server的地址
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    # 应用的名字
    name: order
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config
      profile: dev

如果是远端的RabbitMQ,各个节点,包括config server都要加入以下配置:

spring:
  rabbitmq:
    host: xxx
    port: 5672
    username: xxx
    password: xxx

各个节点的环境变量或者配置类使用了注解@RefreshScope
刷新节点,使用postman发送post请求:
http://127.0.0.1:8888/actuator/bus-refresh

你可能感兴趣的:(2019-08-27/spring cloud bus 自动刷新配置)