zoukankan      html  css  js  c++  java
  • springcloud(8)-消息总线

    1.在view端pom.xml增加如下。

    <!--用于访问路径/actuator/bus-refresh-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    
    <!--用于访问RabbitMQ-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>
    

    2.bootstrap.yml增加

    spring:
        bus:
          enabled: true
          trace:
            enabled: true
    rabbitmq:
      host: localhost
      port: 5672
      username: guest
      password: guest
    

    3.application.yml增加

    management:
      endpoints:
        web:
          exposure:
            include:  "*"
          cors:
            allowed-origins: "*"
            allowed-methods: "*"
    

    4.新增端口检测,在启动类中

    //判断 rabiitMQ 是否启动
    int rabbitMQPort = 5672;
    if(NetUtil.isUsableLocalPort(rabbitMQPort)) {
        System.err.printf("未在端口%d 发现 rabbitMQ服务,请检查rabbitMQ 是否启动", rabbitMQPort );
        System.exit(1);
    }
    

    5.FreshConfigUtil刷新

    public class FreshConfigUtil {
    
        public static void main(String[] args) {
            HashMap<String,String> headers =new HashMap<>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            System.out.println("因为要去git获取,还要刷新config-server, 会比较卡,所以一般会要好几秒才能完成,请耐心等待");
    
            String result = HttpUtil.createPost("http://localhost:8012/actuator/bus-refresh").addHeaders(headers).execute().body();
            System.out.println("result:"+result);
            System.out.println("refresh 完成");
        }
    }
    

    6.打开微服务http://127.0.0.1:8012/products

    image-20201116141238167

    git修改后,运行FreshConfigUtil,刷新http://127.0.0.1:8012/products

    image-20201116141804283
  • 相关阅读:
    [Linux]软件目录
    [Linux]查看Linux内核及发行版本
    [S7706]华为ACL
    [S7706]华为配置DHCP
    QML-密码管理器
    QML-AES加解密小工具
    LaTex中文article模板(支持代码、数学、TikZ)
    Memo-Tech
    VIM学习笔记
    CodeForces 674C Levels and Regions
  • 原文地址:https://www.cnblogs.com/NaoDaiYouDianDa/p/13985419.html
Copyright © 2011-2022 走看看