zoukankan      html  css  js  c++  java
  • springcloud-Hystrix断路器

    1.依赖

            <!--引入hystrix-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            </dependency>
    

     2.服务端

    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableCircuitBreaker
    public class ProductservicesApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ProductservicesApplication.class, args);
        }
    
    }
    
        @RequestMapping("/product/findAll")
        @HystrixCommand(fallbackMethod = "findAllFM")
        public Map findAll() {
            int a = 1 / 0;
            Map map = new HashMap();
            map.put("111", "苹果手机");
            map.put("222", "苹果笔记本");
            map.put("333", "端口" + port);
            return map;
        }
    
        public Map findAllFM() {
            Map map = new HashMap();
            map.put(-1, "服务异常,服务端开启断路器");
            return map;
        }
    

     3.客户端

    feign.hystrix.enabled=true
    
    @FeignClient(value = "productservices",fallback = ProductClientFB.class)
    public interface ProductClient {
        @RequestMapping("/product/findAll")
        public Map findAll();
    }
    
    @Component
    public class ProductClientFB implements ProductClient {
        @Override
        public Map findAll() {
            Map map = new HashMap();
            map.put(-1, "服务异常,客户端开启断路器");
            return map;
        }
    }
    
  • 相关阅读:
    C# 基础笔记
    ASP.Net Jquery 随机验证码 文本框判断
    html 随机验证码
    冒泡排序
    工厂方法模式[Factory Mothod]
    单例设计模式[Singleton]
    设计模式之SOLID原则
    linux下配置zookeeper
    linux中安装nginx
    linux安装tomcat
  • 原文地址:https://www.cnblogs.com/taohaijun/p/13489493.html
Copyright © 2011-2022 走看看