New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call Timeout(OKHTTP) not working for my Open Feign Config. #2342
Comments
@parthiv-groww it looks like you need to add options for your feign client to use the same OkHttpClient:
|
Hello @gromspys , thank you for your response. |
Could you please give your unit test? I tried to reproduce, but it looks like call timeout works as expected:
|
This is my unit test . Even I did try with okhttp client in similar manner and it did work but not with feign client.
And here is how my cdpDao is annotated with Feign client:
One more thing, in the second assert in your code, dont we need to check with "InterruptedIOException.class" |
As I remember feign client has default retryer. In unit test we can change RetryableException to InterruptedIOException:
|
So can you please suggest any changes that we need to do so that we are able to use call timeout? |
It's hard to say what is wrong without full configuration. But it looks like your configuration was ignored:
Try to remove annotation
|
Hey @gromspys
My sample Interface
My sample configs
My pom.xml file
I set a call timeout of 100ms and started a timer to evaluate the exact time the thread runs for. |
It looks like there is default retryer bacause I'm getting 6300 ms. Try to set |
I have made the suggested changes and my call timeout is 10ms but still my total thread duration is somewhat around 90ms (which suggests that call timeout is not working). And I am not getting the required InterruptedIOException. |
Need some time for initialization. Try to call twice in the same test and compare time. To get InterruptedIOException exception use |
This is the changes that I have made, My call timeout is 10ms
and this was my output. |
Looks like the url |
Now this is my config for okhttp
And my config for Feign Client bean
I have a retryer setup at 1000 ms of read or connect Timeout and my call timeout is 10 ms as per the above config. So my retryer should not have been called and call timeout should have been executed. (But I am still getting the InterruptedIoException as expected and my test case is successful). |
Everything works as expected. Retryer was executed by call timeout exception (like 500 server status code). If you don't need to retry, just use Retryer.NEVER_RETRY. |
Here postmapping is not working also and I want to replace it with RequestLine which does not support using more parameters with RequestBody. |
You can find how to do it in documentation https://github.com/OpenFeign/feign |
I have made okhttp config bean and used that for my feign client config. I need to use call timeout in my service and it is not working the way it should. I have also configured read and connect timeout and they are working fine.
@Bean Feign feignBuilder(@Qualifier("cdpOkHttpClient") OkHttpClient cdpOkHttpClient) { return Feign .builder() .client(new feign.okhttp.OkHttpClient(cdpOkHttpClient)) .encoder(new SpringEncoder(messageConverters)) .decoder(new SpringDecoder(messageConverters)) .retryer(new CDPRetryerConfig()) .build(); }
My Okhttp config
`@Bean(name = "baseOkHttpClient")
public OkHttpClient baseOkHttpClient() {
return new OkHttpClient.Builder()
.readTimeout(500, TimeUnit.MILLISECONDS)
.connectTimeout(500, TimeUnit.MILLISECONDS)
.callTimeout(10,TimeUnit.MILLISECONDS)
.build();
}
and I am picking the timeout values from application.yml file
I have also tried using writing unit test to test this configuration. With custom Okhttp bean it works fine but does not work when used with Feign client.
The text was updated successfully, but these errors were encountered: