Day186.Hystrix断路器 -SpringCloud

SpringCloud

十、Hystrix断路器

在这里插入图片描述

在这里插入图片描述


简介

在这里插入图片描述

功能:服务降级服务熔断接近实时的监控,限流,隔离等。


Hystrix重要概念

服务降级(fallback)

提供者和消费者都可以进行服务降级。(一般都是放在客户端(消费者))

在这里插入图片描述

在这里插入图片描述

服务熔断(break)

在这里插入图片描述


在这里插入图片描述

服务限流(flowlimit)

在这里插入图片描述


Hystrix案例

构建

把7001改为单机版,方便后面进行案例测试。

  1. 新建项目cloud-provider-hystrix-payment8001

  2. pom

    <dependencies>
        <!-- hystrix-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <!-- 引用自己定义的api通用包,可以使用Payment支付Entity -->
        <dependency>
            <groupId>com.achang.springcloud</groupId>
            <artifactId>cloud-api-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--监控-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--eureka client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!--热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!--   一个Java工具包     -->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
  3. yml

    server:
      port: 8001
    
    spring:
      application:
        name: cloud-provider-hystrix-payment
    
    eureka:
      client:
        register-with-eureka: true
        fetch-registry: true
        service-url:
          #单机版
          defaultZone: http://localhost:7001/eureka
          #集群版
    #      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
    
  4. 主启动类

    @SpringBootApplication
    @EnableEurekaClient
    public class PaymentHystrixMain8001 {
        public static void main(String[] args) {
            SpringApplication.run(PaymentHystrixMain8001.class,args);
        }
    }
    
  5. service

    @Service
    public class PaymentService {
    
        // 正常访问
        public String paymentInfo_OK(Integer id){
            return "线程池:  "+Thread.currentThread().getName()+"  paymentInfo_OK, id = "+id;
        }
    
    
        //超时访问方法
        public String paymentInfo_timeout(Integer id){
    
            int timeNumber = 3;
    
            try {
                TimeUnit.SECONDS.sleep(timeNumber);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
            return "线程池:  "+Thread.currentThread().getName()+"  paymentInfo_timeout, id = "+id + ",  耗时: "+ timeNumber + "秒";
        }
    }
    
  6. controller

    @RestController
    @Slf4j
    public class PaymentController {
    
        @Resource
        private PaymentService paymentService;
    
        //spring的@Value注解
        @Value(value = "${server.port}")
        private String serverPort;
    
    
        @GetMapping("/payment/hystrix/ok/{id}")
        public String paymentInfo_OK(@PathVariable("id") Integer id){
            String result = paymentService.paymentInfo_OK(id);
            log.info("********* RESULT:"+ result +"***********");
            return result;
        }
    
        @GetMapping("/payment/hystrix/timeout/{id}")
        public String paymentInfo_timeout(@PathVariable("id") Integer id){
            String result = paymentService.paymentInfo_timeout(id);
            log.info("********* RESULT:"+ result +"***********");
            return result;
        }
    
    }
    
  7. 启动7001和8001
    http://localhost:8001/payment/hystrix/ok/1

    在这里插入图片描述


    http://localhost:8001/payment/hystrix/timeout/1

    在这里插入图片描述

在这里插入图片描述


高并发测试

安装JMeter

JMeter下载地址:http://jmeter.apache.org/download_jmeter.cgi

下载tgz和zip都可以:

在这里插入图片描述

进入解压后的目录的bin目录,找到jmeter.properties文件,修改语言zh_CN。

在这里插入图片描述

从终端进入bin目录,输入jmeter.sh运行jmeter

在这里插入图片描述

在这里插入图片描述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WtZegkcU-1612794926768)(C:\Users\PePe\AppData\Roaming\Typora\typora-user-images\image-20210207212859534.png)]


进行高并发测试

测试http://localhost:8001/payment/hystrix/timeout/1

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JNIsCsq0-1612794926773)(C:\Users\PePe\AppData\Roaming\Typora\typora-user-images\image-20210207213519871.png)]

添加发送http请求

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-l6zywwuP-1612794926777)(C:\Users\PePe\AppData\Roaming\Typora\typora-user-images\image-20210207214155172.png)]

然后去访问http://localhost:8001/payment/hystrix/ok/1,访问速度变慢了。

在这里插入图片描述


新建80
  1. 新建cloud-consumer-feign-hystrix-order80

  2. pom

    <dependencies>
        <!-- openfeign -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <!--   hystrix     -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <!--eureka client-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- 引用自己定义的api通用包,可以使用Payment支付Entity -->
        <dependency>
            <groupId>com.angenin.springcloud</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
  3. yml

    server:
      port: 80
    
    eureka:
      client:
        register-with-eureka: false
        service-url:
          defaultZone: http://localhost:7001/eureka
    
    #需要加上,否则会报错
    ribbon:
      ReadTimeout: 4000
      ConnectTimeout: 4000
    
  4. 主启动类

    @SpringBootApplication
    @EnableFeignClients
    @EnableEurekaClient
    public class OrderHystrixMain80 {
        public static void main(String[] args) {
            SpringApplication.run(OrderHystrixMain80.class,args);
        }
    }
    
  5. service

    @Component
    @FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT")
    public interface PaymentHystrixService {
    
        @GetMapping("/payment/hystrix/ok/{id}")
        public String paymentInfo_OK(@PathVariable("id") Integer id);
        
        @GetMapping("/payment/hystrix/timeout/{id}")
        public String paymentInfo_TimeOut(@PathVariable("id") Integer id);
    }
    
  6. controller

    @Slf4j
    @RestController
    public class OrderHystrixController {
    
        @Resource
        private PaymentHystrixService paymentHystrixService;
    
    
        @GetMapping("/consumer/payment/hystrix/ok/{id}")
        public String paymentInfo_OK(@PathVariable("id") Integer id){
            String result = paymentHystrixService.paymentInfo_OK(id);
            return result;
        }
    
        @GetMapping("/consumer/payment/hystrix/timeout/{id}")
        public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
            String result = paymentHystrixService.paymentInfo_TimeOut(id);
            return result;
        }
    
    }
    
  7. 启动80,进行测试
    http://localhost/consumer/payment/hystrix/ok/1

    在这里插入图片描述

    http://localhost/consumer/payment/hystrix/timeout/1

    在这里插入图片描述

  8. 启动jmeter,然后再进行测试

    在这里插入图片描述

故障现象、导致原因以及解决

现象:

在这里插入图片描述


在这里插入图片描述


解决:

在这里插入图片描述


在这里插入图片描述


服务降级

在这里插入图片描述

在这里插入图片描述

提供者

  1. 修改8001中PaymentService的paymentInfo_TimeOut方法,并添加paymentInfo_TimeOutHandler方法:

        //超时访问方法
        /*
          通过@HystrixCommand来指定哪个方法由Hystrix来接管
             fallbackMethod属性: 指定哪个方法作为兜底方法
         */
        @HystrixCommand(fallbackMethod ="paymentInfo_TimeoutHandler", commandProperties = {
                //设置自身超时调用时间的峰值为 3 秒,峰值内可以正常运行,超过了需要有兜底的方法处理,服务降级fallback
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")
        })
        public String paymentInfo_timeout(Integer id){
    
            int timeNumber = 5000;
    
            //int i = 10/0; 测试运行时异常
    
            try {
                TimeUnit.MILLISECONDS.sleep(timeNumber);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
            return "线程池:  "+Thread.currentThread().getName()+"  paymentInfo_timeout, id = "+id + ",  耗时: 秒";
        }
    
    =====================================================================
        
        //服务降级的兜底方法
        public String paymentInfo_TimeoutHandler(Integer id){
            return "线程池:  "+Thread.currentThread().getName()+"  paymentInfo_TimeoutHandler, id = "+id+", 不好意思 ,系统繁忙";
    
        }
    
  2. 然后在8001的主启动类上添加@EnableCircuitBreaker注解,启用断路器。

    @SpringBootApplication
    @EnableEurekaClient
    @EnableCircuitBreaker
    public class PaymentHystrixMain8001 {
        public static void main(String[] args) {
            SpringApplication.run(PaymentHystrixMain8001.class,args);
        }
    }
    
  3. 启动7001和8001,测试8001的fallback,http://localhost:8001/payment/hystrix/timeout/1成功进入fallback方法。(并且fallback方法是用Hystrix的线程池)

    在这里插入图片描述

  4. 去掉sleep,改为 1 / 0,测试方法运行异常,http://localhost:8001/payment/hystrix/timeout/1,也可以进入fallback方法。

    在这里插入图片描述

在这里插入图片描述


消费者

在这里插入图片描述

  1. 在80的yml中添加:

    feign:
      hystrix:
        enabled: true  #老师说是要设置这个,我设置一个不管怎么范围都是超时
    
  2. 在主启动类添加@EnableHystrix注解。

    @SpringBootApplication
    @EnableFeignClients
    @EnableEurekaClient
    @EnableHystrix
    public class OrderHystrixMain80 {
        public static void main(String[] args) {
            SpringApplication.run(OrderHystrixMain80.class,args);
        }
    }
    
  3. 修改OrderHystrixController的paymentInfo_TimeOut方法,并添加paymentTimeOutFallbackMethod方法:

        @GetMapping("/consumer/payment/hystrix/timeout/{id}")
        @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod", commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3500")
        })
        public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
            String result = paymentHystrixService.paymentInfo_TimeOut(id);
            // int i =10/0;
            return result;
        }
    
    =========================================================
        
        public String paymentTimeOutFallbackMethod(@PathVariable("id") Integer id){
            return "消费者80,支付系统繁忙";
        }
    
  4. 启动7001,8001,80,http://localhost//consumer/payment/hystrix/timeout/1(如果是提供者那边出问题,并且消费者设置了fallback,会优先进入消费者的fallback)

    在这里插入图片描述

  5. 在中添加int i = 1 / 0;,运行异常也会进入80的fallback方法。

    在这里插入图片描述


目前的问题和解决办法

在这里插入图片描述


代码膨胀的解决办法

解决办法:设置全局fallback方法。

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述

  1. 在80的OrderHystrixController中添加全局fallback方法:
    //全局fallback方法,不能有传参
    public String payment_Global_FallbackMethod(){
        return "Global异常处理信息,请稍后再试!";
    }
  1. 并在OrderHystrixController类上加上@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod"),指定设置全局fallback方法。

    @RestController
    @Slf4j
    //设置全局fallback,类似统一异常处理
    @DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
    public class OrderHystrixController {}
    
  2. 把paymentInfo_TimeOut方法的@HystrixCommand

        @GetMapping("/consumer/payment/hystrix/timeout/{id}")
        //没有指明具体的降级方法
    //    @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod", commandProperties = {
    //            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
    //    })
        @HystrixCommand //没指明,他就会调用在类上表明的全局降级方法
        public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
            String result = paymentHystrixService.paymentInfo_TimeOut(id);
            int i =10/0;
            return result;
        }
    
  3. 进行测试,http://localhost/consumer/payment/hystrix/timeout/1

    在这里插入图片描述


混乱的解决办法

在这里插入图片描述


在这里插入图片描述


在这里插入图片描述

模拟宕机场景
  1. 在80的service包下新建PaymentFallbackService类,实现PaymentHystrixService接口

    //统一为接口里面的方法进行异常处理
    @Component
    public class PaymentFallbackService implements PaymentHystrixService {
        @Override
        public String paymentInfo_OK(Integer id) {
            return "-----PaymentFallbackService fall back,ooookkkkk paymentInfo_OK--------------";
        }
    
        @Override
        public String paymentInfo_TimeOut(Integer id) {
            return "-----PaymentFallbackService fall back,555555555 paymentInfo_TimeOut--------------";
        }
    }
    
  2. 要在yml中加上:(我们在之前就加上了)

    feign:
      hystrix:
        enabled: true
    
  3. 然后给PaymentHystrixService接口的@FeignClient注解加上fallback = PaymentFallbackService.class属性,用于出错进行fallback处理。

    @Service
    @FeignClient(value = "cloud-provider-hystrix-payment",fallback = PaymentFallbackService.class)
    public interface PaymentHystrixService {
        @GetMapping("/payment/hystrix/ok/{id}")
        public String paymentInfo_OK(@PathVariable("id") Integer id);
    
        @GetMapping("/payment/hystrix/timeout/{id}")
        public String paymentInfo_TimeOut(@PathVariable("id") Integer id);
    }
    
    

    在这里插入图片描述

  4. 启动7001,8001,80,然后先访问``,成功访问

    http://localhost/consumer/payment/hystrix/ok/1

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ERLmfPpM-1612794926784)(C:\Users\PePe\AppData\Roaming\Typora\typora-user-images\image-20210208143624497.png)]

  5. 然后关掉8001,模拟提供者宕机,刷新页面

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LgNaoVgl-1612794926785)(C:\Users\PePe\AppData\Roaming\Typora\typora-user-images\image-20210208143538859.png)]


在这里插入图片描述

简单来说:就是让80调用自己实现接口的方法服务降级返回,而不是一直去连接已经宕机的服务,浪费资源


熔断是一种处理机制,降级是处理办法

服务熔断

在这里插入图片描述

实操

在这里插入图片描述

  1. 在8001的PaymentService中添加

        //====服务熔断
        @HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = {
                @HystrixProperty(name = "circuitBreaker.enabled", value = "true"),                      //开启断路器
                @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),         //请求总数阈值(默认20)
                @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),   //休眠时间窗口期(休眠多久进入半开模式(单位毫秒,默认5秒))
                @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"),       //请求次数的错误率达到多少跳闸(百分率%,默认50%)
        })
        public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
            if(id < 0){
                throw  new RuntimeException("****id 不能为负数");
            }
            String serialNumber = IdUtil.simpleUUID();
    
            return  Thread.currentThread().getName() + "\t" + "调用成功,流水号:" + serialNumber;
        }
        public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id){
            return "id 不能为负数,请稍后再试, id: " + id;
        }
    
  2. 在8001的PaymentController中添加

    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("******result:" + result);
        return result;
    }
    
  3. 启动7001和8001
    http://localhost:8001/payment/circuit/-1(输入超过6次进入熔断)

    在这里插入图片描述


    熔断10秒内就算是正确的请求也返回错误信息

    在这里插入图片描述


    10秒后进入半开模式,对请求进行处理,此时如果是正确的请求,那么就关闭熔断,否则再次进入熔断,10秒后再次开启半开模式,对请求进行处理,直到半开模式处理到正确请求。

    在这里插入图片描述


总结

https://martinfowler.com/bliki/CircuitBreaker.html

在这里插入图片描述

我的总结:

如果请求次数的错误率超过指定值,开启熔断;经过一段时间后(默认:5s)后,变为半开模式;然后放进一个请求进行处理,如果请求处理成功,关闭熔断;如果还是报错,继续进入熔断,再经过一段时间后,变为半开模式,再进行对下一个请求进行处理,一直在熔断,半开模式来回切换,直到请求成功,关闭熔断。


在这里插入图片描述


在这里插入图片描述


官网步骤:

在这里插入图片描述

断路器在什么情况下开始起作用:

https://github.com/Netflix/Hystrix/wiki/How-it-Works

在这里插入图片描述


在这里插入图片描述


断路器开启或关闭的条件:

在这里插入图片描述


断路器打开之后:

在这里插入图片描述


服务限流

会在后面高级篇alibaba的Sentinel讲解。


Hystrix工作流程

https://github.com/Netflix/Hystrix/wiki/How-it-Works

在这里插入图片描述

官方图例:

在这里插入图片描述

上面简单理解:

1、判断是HystrixCommand还是HystrixObservableCommand

2、判断缓存中是否有可用的,有就返回

3、判断熔断器是否打开,有就去⑧步

4、判断是否异常、超时、服务熔断触发服务降级、信号量/线程池,如果有就去⑧步

5、最后都没有就正常返回


服务监控HystrixDashboard

简介

在这里插入图片描述

仪表盘9001

在这里插入图片描述

  1. 新建模块cloud-consumer-hystrix-dashboard9001

  2. pom

    <dependencies>
        <!--   hystrix仪表盘图形化     -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>com.achang.springcloud</groupId>
            <artifactId>cloud-api-common</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--热部署-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    
  3. yml

    server:
      port: 9001
    
  4. 主启动类

    @EnableHystrixDashboard //启用Hystrix仪表板
    @SpringBootApplication
    public class HystrixDashboard9001 {
    
        public static void main(String[] args) {
            SpringApplication.run(HystrixDashboard9001.class, args);
        }
    
    }
    
  5. 启动9001,在浏览器中输入http://localhost:9001/hystrix

    在这里插入图片描述


断路器演示(服务监控hystrixDashboard)

注意:所有微服务提供者都需要在pom中引入监控依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

修改8001

在这里插入图片描述


在需要监控的【8001等】的服务提供者的主启动类中添加:

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class PaymentHystrixMain8001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentHystrixMain8001.class,args);
    }

===================================================================
    
    /**
     * 此配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑
     * ServletRegistrationBean因为SpringBoot的默认路径不是 “/hystrix.stream"
     * 只要在自己的项目里配置上下的servlet就可以了
     */
    @Bean
    public ServletRegistrationBean getServlet() {
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet() ;
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return  registrationBean;
    }
    
===================================================================
    

}

在这里插入图片描述


监控测试

启动9001,7001,8001

  1. 9001监控8001

    http://localhost:8001/hystrix.stream

    在这里插入图片描述

    在这里插入图片描述

    在这里插入图片描述

  2. 在浏览器输入访问:

    http://localhost:8001/payment/circuit/-1

    http://localhost:8001/payment/circuit/1

    1. 在这里插入图片描述


      多次输入http://localhost:8001/payment/circuit/-1错误的访问。

      在这里插入图片描述


      稍微等一会,然后输入正确的访问http://localhost:8001/payment/circuit/1,就会熔断就会关闭。

      在这里插入图片描述

在这里插入图片描述


7色

在这里插入图片描述


1圈

在这里插入图片描述


1线:

在这里插入图片描述


整图说明:

在这里插入图片描述


在这里插入图片描述


整图说明2

在这里插入图片描述


在这里插入图片描述

感谢尚硅谷
https://www.bilibili.com/video/BV18E411x7eT?p=65

原文地址:https://blog.csdn.net/qq_43284469/article/details/113763599

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Nacos 中的参数有很多,如:命名空间、分组名、服务名、保护阈值、服务路由类型、临时实例等,那这些参数都是什么意思?又该如何设置?接下来我们一起来盘它。 1.命名空间 在 Nacos 中通过命名空间(Namespace)+ 分组(Group)+服务名(Name)可以定位到一个唯一的服务实例。 命名
Nacos 支持两种 HTTP 服务请求,一个是 REST Template,另一个是 Feign Client。之前的文章咱们介绍过 Rest Template 的调用方式,主要是通过 Ribbon(负载均衡) + RestTemplate 实现 HTTP 服务调用的,请求的核心代码是这样的: @
Nacos 是 Spring Cloud Alibaba 中一个重要的组成部分,它提供了两个重要的功能:服务注册与发现和统一的配置中心功能。 服务注册与发现功能解决了微服务集群中,调用者和服务提供者连接管理和请求转发的功能,让程序的开发者无需过多的关注服务提供者的稳定性和健康程度以及调用地址,因为这
Spring Cloud Alibaba 是阿里巴巴提供的一站式微服务开发解决方案,目前已被 Spring Cloud 官方收录。而 Nacos 作为 Spring Cloud Alibaba 的核心组件之一,提供了两个非常重要的功能:服务注册中心(服务注册和发现)功能,和统一配置中心功能。 Nac
在 Nacos 的路由策略中有 3 个比较重要的内容:权重、保护阈值和就近访问。因为这 3 个内容都是彼此独立的,所以今天我们就单独拎出“保护阈值”来详细聊聊。 保护阈值 保护阈值(ProtectThreshold):为了防止因过多实例故障,导致所有流量全部流入剩余健康实例,继而造成流量压力将剩余健
前两天遇到了一个问题,Nacos 中的永久服务删除不了,折腾了一番,最后还是顺利解决了。以下是原因分析和解决方案,建议先收藏,以备不时之需。 临时实例和持久化实例是 Nacos 1.0.0 中新增了一个特性。临时实例和持久化实例最大的区别是健康检查的方式:临时实例使用客户端主动上报的健康检查模式,而
Spring Cloud Alibaba 技术体系中的 Nacos,提供了两个重要的功能:注册中心(服务注册与发现)功能和配置中心功能。 其中注册中心解决了微服务调用中,服务提供者和服务调用者的解耦,让程序开发者可以无需过多的关注服务提供者和调用者的运行细节,只需要通过 Nacos 的注册中心就可以
负载均衡通器常有两种实现手段,一种是服务端负载均衡器,另一种是客户端负载均衡器,而我们今天的主角 Ribbon 就属于后者——客户端负载均衡器。 服务端负载均衡器的问题是,它提供了更强的流量控制权,但无法满足不同的消费者希望使用不同负载均衡策略的需求,而使用不同负载均衡策略的场景确实是存在的,所以客
本篇文章为大家展示了如何解决Spring Cloud 服务冲突问题,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。一、背景...
本篇内容主要讲解“spring cloud服务的注册与发现怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“spri...
本篇内容介绍了“Dubbo怎么实现Spring Cloud服务治理 ”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处...
本篇内容主要讲解“SpringCloud相关面试题有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SpringCloud相...
如何分析Spring Cloud Ribbon、Spring Cloud Feign以及断路器,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希
这篇文章主要讲解了“springcloud微服务的组成部分有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“s...
这篇文章主要讲解了“SpringCloud的OpenFeign项目怎么创建”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习...
本篇内容主要讲解“spring cloud oauth3整合JWT后获取用户信息不全怎么办”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带...
怎样解析微服务架构SpringCloud,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。...
这篇文章主要介绍spring cloud中API网关的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!一、服务网关简介1、外观模式客户端...
本篇内容介绍了“Spring Cloud微服务的相关问题有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处...
本文小编为大家详细介绍“spring cloud config整合gitlab如何搭建分布式的配置中心”,内容详细,步骤清晰,细节处理妥当,希望这篇“spring cloud config整合gi...