我想知道是否
resilience4j.timelimiter.instances.feignClienA.timeoutDuration
在resilience4j配置中适用于spring-cloud openfeign feignClienA
的readTimeOut。
我的项目是这样配置的,但是不起作用。我调试的时候发现feign其实是通过feign.SynchronousMethodHandler#findOptions
获取options参数来设置readTimeout的,但是我没有看到在哪里注入这个参数。
resilience4j-feign 中的装饰器只提供了 CircuitBreaker Bulkhead,没有时间限制器。
那么如何让我的配置生效呢?
我的 yaml 配置
## timeout
resilience4j:
timelimiter:
instances:
DataProcessFeignServiceprocessInitializeProcessTaskInitRequest:
timeoutDuration: 240s
cancel-running-future: true
我的假客户
@FeignClient(value = "clearance-data-process-ib", fallbackFactory = DataProcessFeignServiceFallBack.class)
public interface DataProcessFeignService {
@PostMapping("/service/process-task/process-initialize")
@Operation(method = "POST", summary = "initialize")
ServerResponse<Boolean> processInitialize(@Valid @RequestBody ProcessTaskInitRequest request);
}
http测试
@GetMapping("/feignTest")
public ApiResponse<String> feignTest() {
// extracted();
ProcessTaskInitRequest request = new ProcessTaskInitRequest();
request.setDeclarationWaybillIdList(Lists.newArrayList("hello"));
request.setTaskType("DATA_PRESS");
log.info("feignTest request:{}", JsonUtil.toJsonString(request));
dataProcessFeignService.processInitialize(request);
return ApiResponse.success();
}
服务器端睡眠300s
/**
* Initialize
*
* @param request
* @return Response
*/
@PostMapping("/process-initialize")
@Operation(method = "POST", summary = "Initialize")
public ServerResponse<Boolean> processInitialize(@Valid @RequestBody ProcessTaskInitRequest request) {
try {
TimeUnit.SECONDS.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
return ServerResponse.success(Boolean.TRUE);
}
请求应该在 240 秒内超时,但现在它会在大约 60 秒内回退,因为 feign 选项默认为 60 秒。
您可以像这样将配置添加到 application.properties :
spring.cloud.openfeign.client.config.default.read-timeout=300000