栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

OpenFeign超时时间设置最新

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenFeign超时时间设置最新

背景

目前官网最新稳定版本版本3.1.3 CURRENT GA.

GA:(Ggeneral Availability):发行稳定版,官方推荐使用此版本。
SNAPSHOT:快照版,可以稳定使用,且仍在继续改进版本。

超时配置
我们可以在默认客户端和命名客户端上配置超时。OpenFeign 使用两个超时参数:
connectTimeou: 防止由于服务器处理时间长而阻塞调用者。
readTimeout: 从连接建立时开始应用,在返回响应时间过长时触发。

官方原文:

1.3. Timeout Handling We can configure timeouts on both the default and the named client. OpenFeign works with two timeout parameters:

connectTimeout prevents blocking the caller due to the long server processing time.

readTimeout is applied from the time of connection establishment and is triggered when returning the response takes too long.

官网地址:
https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#timeout-handling

如何配置及是否生效查看

源码配置类FeignClientProperties:

@ConfigurationProperties("feign.client")
public class FeignClientProperties {

	private boolean defaultToProperties = true;

	private String defaultConfig = "default";

	private Map config = new HashMap<>();
	...
	
	public static class FeignClientConfiguration {

		private Logger.Level loggerLevel;

		private Integer connectTimeout;

		private Integer readTimeout;

		private Class retryer;
		...

private Map config = new HashMap<>();上打上断点
重要断点流程

JavaBeanBinder—>Binder—>MapBinder

源码会为config增加default的key由此配置是
feign.client.config.default

feign:
  client:
    config:
      default:
        readTimeout: 5000
        connectTimeout: 5000

查看是否生效
配置的值与断点中获取的值呼应上,就配置成功了

扩展

Feign:Netflix公司研发,是SpringCloud组件中的一个轻量级RESTful的HTTP服务客户端,是SpringCloud中的第一代负载均衡客户端。
OpenFeign:SpringCloud研发,在Feign的基础上支持了Spring MVC的注解,如@RequesMapping等等。是SpringCloud中的第二代负载均衡客户端。


OpenFeign github地址:
https://github.com/OpenFeign/feign

问君何事轻离别,一年能几团圆月。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1027560.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号