Skip to content

Latest commit

 

History

History
69 lines (45 loc) · 2.63 KB

File metadata and controls

69 lines (45 loc) · 2.63 KB
  1. 项目地址

  2. 配置

    • client

      • application.yml增加配置 地址

        feign:
          hystrix:
            enabled: true
      • 启动类增加注解启动Hystrix 地址

        @EnableHystrix //激活Hystrix
      • 在client server类上面增加注解 地址

        @FeignClient(name = "spring-cloud-eureka-server",fallback = FallBackDefault.class)
      • 实现熔断方法,比如我上方指定的熔断方法是FallBackDefault.class 地址

        @Component  //注意注解,增加到spring 容器
        public class FallBackDefault implements   ClientSayServer{
            @Override
            public String sayinfo() {
                return "熔断了.当前方法:{sayinfo}";
            }
        
            @Override
            public User save(User user) {
                return null;
            }
        
            @Override
            public String getMessageById(String id) {
                return "熔断了.当前方法:{getMessageById}";
            }
        }
    • server

      暂无

    1. 访问http://localhost:8846/fallback/feign?id=sadas会出现熔断和非熔断的情况

    2. 注意

      • feign默认超时时间是1秒,所以如果需要修改超时时间需要在网上查询配置
      • application.yml注册的eureka,我是用的docker-compose,所以在windows下需要改一下eureka的注册地址