Ribbon懒加载第一次超时、异常问题

Ribbon懒加载第一次超时、异常问题

1、问题描述

由于Ribbon懒加载,导致第一次服务调用超时报错。这里我们直接看异常吧!

2020-05-10 07:55:55.096  INFO [user-service,e8a466a5aba3cb44,9781723607238219,true] 14544 --- [x-uaa-service-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client uaa-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=uaa-service,current list of Servers=[root-PC:9999],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;	Instance count:1;	Active connections count: 0;	Circuit breaker tripped count: 0;	Active connections per server: 0.0;]
},Server stats: [[Server:root-PC:9999;	Zone:defaultZone;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 08:00:00 CST 1970;	First connection made: Thu Jan 01 08:00:00 CST 1970;	Active Connections:0;	total failure count in last (1000) msecs:0;	average resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@256c241c
--------opps getToken hystrix---------

嗯,直接超时降级了。

在这里插入图片描述
但是你再一次发送请求的时候,就成功了。

在这里插入图片描述

2、问题解决

# 服务启动时加载
ribbon:
  eager-load:
    enabled: true

在这里插入图片描述

在yml配置文件中添加这个配置即可。再次启动发现正常。

在这里插入图片描述

3、总结

  书上的代码直接运行绝大部分是对的,但是总有一些软件的更新使得作者无能为力。之前的API是对的,但是之后就废弃了或修改了是常有的事。所以我们需要跟踪源代码。这只是一个小小的问题,如果没有前辈的无私奉献,很难想象我们自己一天能学到多少内容。感谢各位前辈的辛勤付出,让我们少走了很多的弯路!

点个赞再走呗!欢迎留言哦!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章