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/服务名:端口号"
相关推荐
烛阴3 小时前
bignumber.js深度解析:驾驭任意精度计算的终极武器
前端·javascript·后端
服务端技术栈3 小时前
电商营销系统中的幂等性设计:从抽奖积分发放谈起
后端
Chan164 小时前
【 SpringCloud | 微服务 MQ基础 】
java·spring·spring cloud·微服务·云原生·rabbitmq
你的人类朋友4 小时前
✍️Node.js CMS框架概述:Directus与Strapi详解
javascript·后端·node.js
面朝大海,春不暖,花不开4 小时前
自定义Spring Boot Starter的全面指南
java·spring boot·后端
钡铼技术ARM工业边缘计算机5 小时前
【成本降40%·性能翻倍】RK3588边缘控制器在安防联动系统的升级路径
后端
斯普信云原生组5 小时前
Docker构建自定义的镜像
java·spring cloud·docker
CryptoPP5 小时前
使用WebSocket实时获取印度股票数据源(无调用次数限制)实战
后端·python·websocket·网络协议·区块链
白宇横流学长5 小时前
基于SpringBoot实现的大创管理系统设计与实现【源码+文档】
java·spring boot·后端
草捏子6 小时前
状态机设计:比if-else优雅100倍的设计
后端