cloud config + bus

简介: cloud config + bus

一、native本地配置,通过服务发现去找配置中心

1、服务端(config-server)

  • 添加依赖
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
  • 启动类添加注解:@EnableConfigServer

  • bootstrap.yml关键部分配置:

spring:
  profiles:
    active: native         # native 表示从本地获取配置文件
    include: local
---
spring:
  profiles: local
  cloud:
    config:
      server:
        native:
          search-locations: classpath:config/local/
  • 在resources文件夹下创建文件夹并添加配置文件: config/local
|resources
|--config
|----local
|-----application-local.yml       # 所有模块共享的配置,单个模块个性化配置可以再下方具体配置文件中覆盖此文件
|-----order-server-local.yml      # 指定模块个性化配置,优先级最高

2、客户端(order-server)

  • 添加依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    
  • 配置文件中添加:

spring:
  cloud:
    config:
      discovery:
        enabled: true                 # 通过服务发现的方式去找配置中心
        service-id: config-server      
      profile: local
      #username: yourusername
      #password: yourpassword

二、使用git地址

除了yml配置不一样,其他的与上面保持一致

1、git仓库目录:

|config
|--local
|----application-local.yml
|----order-server-local.yml
|--dev
|----application-dev.yml
|----order-server-dev.yml
|--test
|--master

2、服务端yml配置

spring:
  profiles: local        # local配置
  cloud:
    config:
      server:
        git:
          uri: http://***/config-server.git
          username: yourusername
          password: yourpassword
          search-paths: /config/local            # 使用local中配置

3、客户端yml配置

与第一种情况保持一致即可,这里不需改变

三、Spring Cloud Bus

1、客户端与服务端都引入依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

2、客户端与服务端都添加配置

spring:
  profiles: local
  cloud:
      # server配置这里省略 
      # bus配置,还需要rabbitmq的支持
    bus:
      enabled: true
      refresh:
        enabled: true
  rabbitmq:
    host: server-pc1
    port: 5672
    username: username
    password: password

3、启动eureka、config、order-port1、order-port2

  • 修改配置后单独刷新模块order-port1、order-port2,查看是否生效
  • 修改配置后,只调用config的bus-refresh,查看所有客户端是否都被刷新了
bus刷新地址:               IP:port/actuator/bus-refresh
带有security认证的地址:  username:password@IP:port/actuator/bus-refresh
相关文章
|
8天前
|
消息中间件 SpringCloudAlibaba Java
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(八)Config服务配置+bus消息总线+stream消息驱动+Sleuth链路追踪
【Springcloud Alibaba微服务分布式架构 | Spring Cloud】之学习笔记(八)Config服务配置+bus消息总线+stream消息驱动+Sleuth链路追踪
802 0
|
8天前
|
Java API Nacos
spring.config.import 是一个 Spring Cloud Config Server 的属性,
spring.config.import 是一个 Spring Cloud Config Server 的属性,【1月更文挑战第25天】【1月更文挑战第123篇】
72 1
|
8天前
|
Java 开发工具 git
|
8月前
|
存储 消息中间件 Java
Spring Boot 中的 Spring Cloud Config
Spring Boot 中的 Spring Cloud Config
|
10月前
|
监控 Java 开发工具
SpringCloud极简入门-配置中心Spring Cloud Config
在分布式系统中,由于服务数量很多,为了方便服务配置文件统一管理我们需要用到置中心组件。在Spring Cloud中,分布式配置中心组件spring cloud config 它可以帮我们集中管理配置文件,修改配置无需重启服务 等,它支持配置文件放在配置服务的本地,也支持放在远程如Git仓库中集中管理。在spring cloud config 分为了服务端 config server和客户端config client 两个角色。
314 0
|
12月前
|
存储 负载均衡 前端开发
Spring Cloud【Finchley】实战-05配置中心的搭建(配合使用Eureka)和Config Server高可用
Spring Cloud【Finchley】实战-05配置中心的搭建(配合使用Eureka)和Config Server高可用
176 0
BXA
|
存储 安全 Java
Spring Cloud Config实现配置中心
Spring Cloud Config是一个开源项目基于Git或Subversion等版本控制工具提供分布式系统的外部化配置支持。它能够帮助架构师和开发人员管理所有微服务的配置,提供安全的、可伸缩的、高可用的分布式配置中心服务
BXA
131 0
|
消息中间件 前端开发 Java
Spring Cloud Config(Greenwich版本)基于数据库搭建统一配置中心
Spring Cloud Config(Greenwich版本)基于数据库搭建统一配置中心
95 0
|
8天前
|
Java 数据库连接 开发工具
web后端-SpringCloud-Config分布配置
web后端-SpringCloud-Config分布配置
|
8天前
|
API
在vite.config.js 配置代理
在vite.config.js 配置代理
109 2

热门文章

最新文章