SpringCloud-Bus

一、介绍

(1)bus搭配config可以实现客户端配置自动刷新

(2)bus支持两种消息代理,rabbitmq和kafka

(3)使用topic模式分发消息

二、项目搭建(广播)

(1)客户端和服务配置中心pom.xml增加依赖

java 复制代码
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

(2)修改客户端的bootstrap.yml,添加rabbitmq配置、暴露actuator的refresh端点

java 复制代码
server:
  port: 3355

spring:
  application:
    name: cloud-config-client-service
  cloud:
    config:
      label: master #分支名
      name: application # - 号前缀
      profile: prod # - 号后缀
      uri: http://localhost:3344 #配置中心地址
  rabbitmq:
    host: 192.168.0.166
    port: 5672
    username: guest
    password: guest

eureka:
  client:
    #    客户端设置为true
    register-with-eureka: true
    #    客户端设置为true
    fetch-registry: true
    service-url:
      #      defaultZone: http://localhost:7001/eureka
      defaultZone: http://eureka1.com:7001/eureka, http://eureka2.com:7002/eureka
  instance:
    instance-id: configClient3355
    prefer-ip-address: true

management:
  endpoints:
    web:
      exposure:
        include: "*"

(3)修改配置中心服务端的bootstrap.yml,暴露actuator的bus-refresh端点

java 复制代码
server:
  port: 3344

spring:
  application:
    name: cloud-config-service
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/feifanwsh/config.git
      label: master
  rabbitmq:
    host: 192.168.0.166
    port: 5672
    username: guest
    password: guest

eureka:
  client:
    #    客户端设置为true
    register-with-eureka: true
    #    客户端设置为true
    fetch-registry: true
    service-url:
      #      defaultZone: http://localhost:7001/eureka
      defaultZone: http://eureka1.com:7001/eureka, http://eureka2.com:7002/eureka
  instance:
    instance-id: config3344
    prefer-ip-address: true

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

(4)运行

java 复制代码
curl -X POST "http://localhost:3344/actuator/bus-refresh"

三、单播

运行

java 复制代码
curl -X POST "http://localhost:3344/actuator/bus-refresh/服务名:端口号"
相关推荐
Rain50914 分钟前
2.1 Nest.js 项目初始化与模块化架构
开发语言·前端·javascript·后端·架构·数据分析·node.js
cjp56018 分钟前
009. ASP.NET WEB API 用户关联esp32设备
前端·后端·asp.net
贺国亚24 分钟前
Text-to-SQL与Analytics-Agent
后端
一只叫煤球的猫42 分钟前
ThreadForge 源码解读二:一个 Task 从 submit 到完成,内部到底发生了什么?
java·后端·面试
苏三说技术1 小时前
AgentScope Java 2.0 正式发布了!
后端
ping某1 小时前
一个“日志备份”需求,为什么会牵出整个 Linux 日志系统?
后端·架构
血小溅2 小时前
Spring AI 对 Skill/MCP 的支持全景整理
后端
晓杰'2 小时前
从0到1实现Balatro游戏后端(8):Skip Blind与Tag奖励机制设计与实现
后端·websocket·typescript·项目实战·nestjs·状态管理·游戏服务器
叫我:松哥2 小时前
基于Flask框架的校园二手书籍交易平台,注重校园场景的特殊需求,通过学号认证保障用户真实性
后端·python·sqlite·flask·bootstrap
终将老去的穷苦程序员2 小时前
基于SpringBoot的餐饮管理系统
java·spring boot·后端