在之前feign项目上改造一下,
加上依赖:
1 2 3 4
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
|
1 2 3 4 5 6 7 8 9 10
| import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping;
@FeignClient(name = "hystrix-provider", fallback = FeClientFallback.class) public interface FeClient {
@GetMapping("/api") String consumer();
}
|
1 2 3 4 5 6 7 8 9 10
| import org.springframework.stereotype.Component;
@Component public class FeClientFallback implements FeClient{
@Override public String consumer() { return "An error occurred"; } }
|
如果把provider服务关掉,consumer就会返回FeClientFallback
中自定义的内容。
本文源码