Feign builder timeouts not working

旧时模样 提交于 2020-01-02 10:00:50

问题


We are using Netflix feign to connect to a downstream client, but our request.options connect and read timeouts are not working.

This is how we are passing parameters to the builder

Feign.builder()
.client(new OkHttpClient(okHttpClient))
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
.options(new Request.Options(connectTimeoutInMS, readTimeoutInMs)
.target(*,*);

We have set readTimeout and ConnectionTimeout to 1 sec. But what we see is even when the target takes more than 1 sec to respond, it does not timeout and keeps trying to connect.


回答1:


Your request options configurations are not working because you're defining an OkHttpClient, according to Feign's documentation:

OkHttpClient directs Feign's http requests to OkHttp, which enables SPDY and better network control.

So, if your OkHttpClient doesn't have defined these values, it will take defaults values, this value is 10000ms (you can find these values at line 373 here: https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/OkHttpClient.java). So, you should configure your OkHttpClient like:

OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(timeout, TimeUnit.MILLISECONDS); okHttpClient.setReadTimeout(timeout, TimeUnit.MILLISECONDS); okHttpClient.setWriteTimeout(timeout, TimeUnit.MILLISECONDS);



来源:https://stackoverflow.com/questions/35571015/feign-builder-timeouts-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!