-
项目地址
-
配置
-
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
暂无
-
访问
http://localhost:8846/fallback/feign?id=sadas会出现熔断和非熔断的情况 -
注意
feign默认超时时间是1秒,所以如果需要修改超时时间需要在网上查询配置application.yml注册的eureka,我是用的docker-compose,所以在windows下需要改一下eureka的注册地址
-