栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

java Bus配置

java Bus配置

java Bus配置
  • springCloud学习记录
  • Bus(消息总线)
  • 服务端
      • pom
      • yml
      • 启动类
  • 客户端
      • pom
      • yml
      • 启动类
      • 方法类获取配置信息

springCloud学习记录 Bus(消息总线)

在SpringCloud config的基础上实现多台服务器修改,需要用到rabbitmq,git上的配置信息存到rabbitmq里面,git更新后更新到rabbitmq,客户端从rabbitmq里面取

服务端 pom
        
            org.springframework.cloud
            spring-cloud-starter-bus-amqp
        
yml
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
        
            org.springframework.cloud
            spring-cloud-starter-bus-amqp
        
yml
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:服务名称

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/457672.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号