• SpringCloud-Bus


    一、介绍

    (1)bus搭配config可以实现客户端配置自动刷新
    (2)bus支持两种消息代理,rabbitmq和kafka
    (3)使用topic模式分发消息

    二、项目搭建(广播)

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

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-bus-amqp</artifactId>
            </dependency>
    
    • 1
    • 2
    • 3
    • 4

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

    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: "*"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

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

    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"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    (4)运行

    curl -X POST "http://localhost:3344/actuator/bus-refresh"
    
    • 1

    三、单播

    运行

    curl -X POST "http://localhost:3344/actuator/bus-refresh/服务名:端口号"
    
    • 1
  • 相关阅读:
    可变参数函数,initializer_list,省略号形参
    es中的写入速度优化
    【Adobe Illustrator 教程】1. 认识AI并创建第一张画布
    ssm+vue+elementUI 医药进出口交易系统-#毕业设计
    Learn Prompt-什么是ChatGPT?
    1000套web前端期末大作业 HTML+CSS+JavaScript网页设计实例 企业网站制作【建议收藏】
    Hive【Hive(一)DDL】
    C# 图像处理 添加水印
    ubuntu操作系统之新手操作必看篇
    Java之juc旅途-Executor(四)
  • 原文地址:https://blog.csdn.net/qq_25243147/article/details/133840338