GuLi Mall-SpringCloud-OpenFeign-log, timeout configuration

Here we write the feign interface on the service provider side

The advantage is good reusability 

/*
* 关于feign接口,是写在服务提供者一端还是,服务消费者一端?
* feign接口可以写在服务提供者一端,也可以写在服务消费者一端,
* 因为启动类的指定了feign接口所在的位置,但是建议写在服务提供者一端,
* 这样feign接口就可以复用,避免重复编写代码。
* 可以写在独立的服务提供者的api服务提供者模块,同样可以代码复用。
*/

Log configuration:


Timeout configuration:

First do not configure timeout, simulate timeout

Connection timeout and read timeout:

连接超时:ConnectTomeout
时间不易过长:让用户配置建连阶段的最长等待时间,一般来说,TCP三次握手建立连接需要的时间非常短,通常在毫秒级最多至秒级,因此,设置(1~9秒)即可。如果是纯内内网用的话,这个参数可以更短,在下游服务离线无法连接的时候,可以快速失败。
排查服务端/Nginx:通常情况下,客户端负载均衡来连服务端,会直接建立连接,此时出现连接超时大概率是服务端的问题;而如果服务端通过类似Nginx反向代理来负载均衡,客户端连接的其实是Nginx,而不是服务端,此时连接超时排查Nginx。

读取超时:ReadTimeout
等待远端返回数据的时间,包括远端程序处理的时间;解决需要考虑下游服务的服务标准和自己的服务标准,设置合适的读取超时时间。
重试:因为HTTP协议中GET请求表示数据查询操作,无状态,并且考虑到常见的网络丢包现象,HTTP客户端或代理服务器会自动重试GET/HEAD请求。
注意:
读取超时时,只要服务端收到请求,网络层面的超时和断开不会影响服务端的执行。因此,出现读取超时不能随意假设服务端的处理情况,需要根据业务状态考虑如何进行后续处理。
读取超时是数据传输的最长耗时+服务端处理业务逻辑的时间。
读取超时设置根据实际情况,对于定时任务和异步任务,超时配置长些问题不大。微服务中短平快的同步接口调用,并发较大,应设置一个较短的读取超时时间,防止被下游服务拖慢,通常不会设置超过30秒。过长会让下游抖动影响到自己,过短可能影响成功率。

https://www.cnblogs.com/cgy-home/p/15649193.html


Since connectTimeout is a network connection, it is inconvenient to test. So here only test readTimeout request processing timeout.

Since readTimeoutthe request is processed and the response is timed out, that is, it occurs at the service provider ( 服务消费方to call服务

提供方interface, 服务提供方the response interface processes the request and makes a response time limit).

https://caidong.blog.csdn.net/article/details/128066599?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-15-128066599-blog-128723459.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-15-128066599-blog-128723459.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=18

OpenFeign timeout configuration_openfeign timeout configuration_TheFeasterfromAfar's Blog-CSDN Blog


source code:

openFeign actually has a default timeout time, the default is the connection timeout time 10秒, read timeout time 60秒, the source code is in

feign.Request.Options#Options()in this method

How to set OpenFeign request timeout_openfeign timeout setting_Aiqinkid's Blog-CSDN Blog

Talk about the timeout and retry of openfeign_openfeign retry times configuration_jungechat technology blog-CSDN blog

https://www.cnblogs.com/qbbit/p/16342759.html

OpenFeign combat: What are the advanced ways of using OpenFeign components? _ Sectional printing feignclient entry and exit_-Parking blog-CSDN blog

The timeout solution caused by the initialization operation when feign is called for the first time


test:

If you do not configure the timeout, the default is 60s, and an error will be reported if it exceeds 60s. The setting I tested here is 70s

After waiting for 70s, an error message appears: 

Test with browser:


Formal timeout configuration:

Add timeout configuration to consumer-side member microservices

feign:
  client:
    config:
      default: #默认配置
        readTimeout: 2000 #读取超时时间
        connectTimeout: 2000 #连接超时时间ms

postman test: 

An error message appears in 2 seconds, indicating that the configuration is successful: 

Guess you like

Origin blog.csdn.net/ZHOU_VIP/article/details/129624187