Question/Enhancement: Is there any way to have a Per-Request Timeout for a Feign Client?

My current workaround is to create two API Clients, with a different Configuration:

@FeignClient(
    name = "slow-api-calls",
    configuration = [SlowCallsClientConfig::class]
)
class SlowCallsClientConfig {

    @Bean
    fun options() = Request.Options(5000, 5000)
}

If there is no better solution, what would a good implementation look like?

  1. org.springframework.cloud.openfeign.support.SpringMvcContract is using "@RequestMapping", which is the same Annotation for Controller (request-handling classes) mappings. To add Client-Timeouts there would be misplaced.

  2. I could also add a custom AnnotatedParameterProcessor which processes a custom Annotation like @RequesTimeout, but that's feels like another workaround.

  3. https://github.com/OpenFeign/feign/issues/562 will introduce a new @ApiTimeout annoation, which could be picked up by SpringMvcContract

Comment From: ryanjbaxter

I would say option 3 is the best IMO.

Comment From: matt62king

OpenFeign supports adding Request.Options as a method parameter.

https://github.com/OpenFeign/feign/pull/970

Comment From: rowi1de

Thanks @matt62king https://github.com/OpenFeign/feign/pull/970