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;
        }
    }
    
  • 相关阅读:
    shell 字符串替换
    shell 拆分字符串成数组 放入数组
    shell 换行输出变量 换行
    Linux shell修改xml文件
    Spark 实现共同好友
    Hive 开启 service2 服务
    hive 求相互是好友.
    Linux 查看外网ip
    Termux下开启kex远程桌面
    Termux开启ssh服务
  • 原文地址:https://www.cnblogs.com/taohaijun/p/13489493.html
Copyright © 2011-2022 走看看