• 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
  • 相关阅读:
    阿里云Centos 8.2安装LNMP环境
    TP6中缓存的使用
    TP6中命令行
    TP6中请求和响应
    TP6模型操作
    TP6中数据库操作
    TP6中验证器的使用
    TP6如何使用文件上传
    3. Longest Substring Without Repeating Characters
    1. Two Sum
  • 原文地址:https://www.cnblogs.com/NaoDaiYouDianDa/p/13985419.html
Copyright © 2020-2023  润新知