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;
        }
    }
    
  • 相关阅读:
    Iscroll滑动无效
    原生js 无缝滚动组件
    原生 js dialog弹窗组件
    html5 历史管理
    html5拖拽属性
    highcharts 数据图设置X轴间隔显示效果
    highcharts柱状图含有正负柱设置不同颜色的方法
    移动端滑动插件 swiper
    千分位添加和去掉方法
    dubbo常用类和路径
  • 原文地址:https://www.cnblogs.com/taohaijun/p/13489493.html
Copyright © 2011-2022 走看看