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/服务名:端口号"
相关推荐
你的人类朋友2 小时前
✍️【Node.js程序员】的数据库【索引优化】指南
前端·javascript·后端
迢迢星万里灬5 小时前
Java求职者面试:微服务技术与源码原理深度解析
java·spring cloud·微服务·dubbo·netty·分布式系统
why技术6 小时前
翻译翻译,什么叫“编程专用”的显示器?
前端·后端
野生技术架构师7 小时前
SpringBoot集成Tess4j :低成本解锁OCR 图片识别能力
spring boot·后端·ocr
天天摸鱼的java工程师7 小时前
要在 Spring IoC 容器构建完毕之后执行一些逻辑,怎么实现
后端
程序猿小D7 小时前
第25节 Node.js 断言测试
后端·node.js·log4j·编辑器·vim·apache·restful
sg_knight7 小时前
Ribbon负载均衡实战指南:7种策略选择与生产避坑
java·spring boot·spring·spring cloud·微服务·ribbon·负载均衡
shengjk18 小时前
一文搞懂 TCP TCP/IP 和 TCP/IP网络分层之间的联系和区别
后端
述雾学java9 小时前
Spring Boot + Vue 前后端分离项目解决跨域问题详解
vue.js·spring boot·后端