<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>
hystrix:
command:
# default: #全局配置服务配置超时
# execution:
# isolation:
# thread:
# timeoutInMilliseconds: 5000
feignHystrixTestOverTime: #单独为某个方法配置超时时间
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
feign: #feign使用Hystrix
hystrix:
enabled: true
client:
config:
feignHystrixTestOverTime:
connectTimeout: 3000
readTimeout: 3000
@RestController
@RequestMapping("/Hystrix")
public class HystrixFeignController {
@Autowired
private RibbonServerClient ribbonServerClient;
@GetMapping("/FeignHystrixTestOverTime")
@HystrixCommand
public String feignHystrixTestOverTime() {
return ribbonServerClient.feignOverTime();
}
@FeignClient(name = "server", fallback = RibbonServerClient.RibbonServerFallback.class)
public interface RibbonServerClient {
/**
* 测试请求 Feign 使用 Hystrix
* @Method: GET
* @author show
* @date 18:12 2019/6/19
* @return java.lang.String
*/
@GetMapping("/HystrixServer/HystrixOverTimeTest")
String feignOverTime();
/**
* 服务降级触发类
* @author xuanweiyao
* @date 18:15 2019/6/19
* @Component 作为组件
*/
@Component
@Slf4j
class RibbonServerFallback implements RibbonServerClient {
@Override
public String feignOverTime() {
// 触发服务降级返回
log.info("feign接口请求异常,触发断路器,返回null");
return "feign接口请求异常,触发断路器,返回null";
}
}
}
请求过去的服务是延时2秒返回的,不知道为什么feign不能针对方法名进行超时配置。
请问老师,feign应该如何针对方法名配置。
SpringCloud组件实现微服务,【已升级Finchley.Release】
了解课程