spring-cloudresilience4jspring-cloud-circuitbreaker

resilience4J and springcloud-openfeign readTimeOut


I want to know whether resilience4j.timelimiter.instances.feignClienA.timeoutDuration in resilience4j configuration works for readTimeOut of spring-cloud openfeign feignClienA. My project is configured like this but it doesn't work. When I debugged, I found that feign actually gets the options parameter through feign.SynchronousMethodHandler#findOptions to set readTimeout, but I don't see where to inject this parameter. The decorator in resilience4j-feign only provides CircuitBreaker Bulkhead and no timelimiter.

So how can I make my configuration take effect?

my yaml configs

## timeout
resilience4j:
  timelimiter:
    instances:
      DataProcessFeignServiceprocessInitializeProcessTaskInitRequest:
        timeoutDuration: 240s
        cancel-running-future: true

my feign client


@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 test

    @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();
    }

server side sleep 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);
    }

The request should time out in 240 seconds, but now it falls back in about 60 seconds because the feign option defaults to 60 seconds.


Solution

  • You can add config to application.properties like so :

    spring.cloud.openfeign.client.config.default.read-timeout=300000