伪装生成器超时不起作用 [英] Feign builder timeouts not working

查看:110
本文介绍了伪装生成器超时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Netflix feign连接到下游客户端,但是我们的request.options连接和读取超时不起作用.

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(*,*);

我们已将readTimeout和ConnectionTimeout设置为1秒. 但是我们看到的是,即使目标花费了1秒钟以上的时间做出响应,它也不会超时并且会继续尝试连接.

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.

推荐答案

根据Feign的文档,您的请求选项配置不起作用,因为您正在定义OkHttpClient:

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

OkHttpClient将Feign的http请求定向到OkHttp,从而启用SPDY和更好的网络控制.

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

因此,如果您的OkHttpClient尚未定义这些值,它将采用默认值,该值为10000ms(您可以在第373行找到这些值:

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);

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

这篇关于伪装生成器超时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆