feign
feign copied to clipboard
Unable to override default timeout for hystrix.
I am using combination of (open-feign) and (feign-hystrix) to communicate with another micro service. For some requests, It's taking longer(3s) to get a response and as a result I am getting hystrix runtime exception saying "getting timed out and no fall back available". So inorder to bump up the timeout I have added the following property in the yml file
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 10000
But feign is not considering the timeout mentioned in the yml file. I have also tried using the Request.options but was unsuccessful in that as well. Is there any configuration that I have to do to override the default timeout?
@Builder
public class FeignBasicConfig {
Builder baseFeignConfig() {
return HystrixFeign.builder()
.encoder(new JacksonEncoder(objectMapper))
.decoder(new JacksonDecoder(objectMapper))
.options(new Options(5000L, TimeUnit.MILLISECONDS, 5000L, TimeUnit.MILLISECONDS, false))
.retryer(new Retryer.Default(200, SECONDS.toMillis(5), 5));
}
}
@Configuration
@RequiredArgsConstructor
public class UsersClientConfig {
private final FeignConfig feignConfig;
@Bean
public UsersClient usersClient(
@Value("${services.usersClient.baseUrl:#{null}}") String url,
@Value("${services.usersClient.username:#{null}}") String username,
@Value("${services.usersClient.password:#{null}}") String password) {
return feignConfig
.baseFeignConfig()
.requestInterceptor(new BasicAuthRequestInterceptor(username,password))
.target(UsersClient.class, url);
}
}
public interface UsersClient {
@RequestLine("GET /users/{userId}")
CompletableFuture<UsersClientDto> getUserById(@Param("userId") String userId);
}
Our Options
object does not apply to Hystrix specific timeouts at the command group level. You will need to configure them directly in the Hystrix Configuration. In this case you need to consider additional settings to get what you need. Look at the Thread Pool documentation for Hystrix for more information.
Also, I recommend not using our Options
if you are using Hystrix. They will conflict.
I needed to set up timeouts for Hystrix too and documented my findings on StackOverflow.
The Hystrix configuration integration has always left something to be desired, due to the nature of Hystrix and how it defines capabilities at the command key level. Good find. I'll update our documentation with your findings.