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是對的,但是之後就廢棄了或修改了是常有的事。所以我們需要跟蹤源代碼。這只是一個小小的問題,如果沒有前輩的無私奉獻,很難想象我們自己一天能學到多少內容。感謝各位前輩的辛勤付出,讓我們少走了很多的彎路!

點個贊再走唄!歡迎留言哦!

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