国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Spring Cloud重試機制與各組件的重試總結

Spring Cloud重試機制與各組件的重試總結

2021-02-23 11:19周立_itmuch Java教程

這篇文章主要給大家介紹了關于Spring Cloud中重試機制與各組件的重試的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。

springcloud重試機制配置

首先聲明一點,這里的重試并不是報錯以后的重試,而是負載均衡客戶端發現遠程請求實例不可到達后,去重試其他實例。

Spring Cloud重試機制與各組件的重試總結

?
1
2
3
4
5
6
7
8
@bean
@loadbalanced
resttemplate resttemplate() {
  httpcomponentsclienthttprequestfactory httprequestfactory = new httpcomponentsclienthttprequestfactory();
  httprequestfactory.setreadtimeout(5000);
  httprequestfactory.setconnecttimeout(5000);
  return new resttemplate(httprequestfactory);
}

Spring Cloud重試機制與各組件的重試總結

feign重試機制

feign默認是通過自己包下的retryer進行重試配置,默認是5次

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package feign;
 
import static java.util.concurrent.timeunit.seconds;
 
/**
 * cloned for each invocation to {@link client#execute(request, feign.request.options)}.
 * implementations may keep state to determine if retry operations should continue or not.
 */
public interface retryer extends cloneable {
 
 /**
  * if retry is permitted, return (possibly after sleeping). otherwise propagate the exception.
  */
 void continueorpropagate(retryableexception e);
 
 retryer clone();
 
 public static class default implements retryer {
 
  private final int maxattempts;
  private final long period;
  private final long maxperiod;
  int attempt;
  long sleptformillis;
 
  public default() {
   this(100, seconds.tomillis(1), 5);
  }
 
  public default(long period, long maxperiod, int maxattempts) {
   this.period = period;
   this.maxperiod = maxperiod;
   this.maxattempts = maxattempts;
   this.attempt = 1;
  }

feign取消重試

?
1
2
3
4
@bean
retryer feignretryer() {
return retryer.never_retry;
}

feign請求超時設置

?
1
2
3
4
5
6
7
@bean
request.options requestoptions(configurableenvironment env){
  int ribbonreadtimeout = env.getproperty("ribbon.readtimeout", int.class, 6000);
  int ribbonconnectiontimeout = env.getproperty("ribbon.connecttimeout", int.class, 3000);
 
  return new request.options(ribbonconnectiontimeout, ribbonreadtimeout);
}

spring cloud中各組件的重試

最近挺多童鞋問我如何配置spring cloud xxx組件的重試。本篇進行一個總結。

spring cloud中的重試機制應該說是比較混亂的,不同的版本有一定區別,實現也不大一樣,好在spring cloud camden之后已經基本穩定下來,dalston中又進行了一些改進,詳情暫且不表。

下面我們來詳細探討。

筆者使用的版本是 spring cloud dalston sr4 ,同樣適應于edgware 以及更高版本,對于dalston 此前的版本,本文不做討論,大家可自行研究。

ribbon+resttemplate的重試

對于整合了ribbon的resttemplate,例如一個resttemplate添加了@loadbalanced 注解:

?
1
2
3
4
5
6
7
8
@bean
@loadbalanced
public resttemplate resttemplate() {
 simpleclienthttprequestfactory simpleclienthttprequestfactory = new simpleclienthttprequestfactory();
 simpleclienthttprequestfactory.setconnecttimeout(1000);
 simpleclienthttprequestfactory.setreadtimeout(1000);
 return new resttemplate(simpleclienthttprequestfactory);
}

在此基礎上,使用如下配置,即可實現重試:

?
1
2
3
4
5
6
7
8
9
10
11
12
spring:
 cloud:
 loadbalancer:
  retry:
  enabled: true
ribbon:
 # 同一實例最大重試次數,不包括首次調用
 maxautoretries: 1
 # 重試其他實例的最大重試次數,不包括首次所選的server
 maxautoretriesnextserver: 2
 # 是否所有操作都進行重試
 oktoretryonalloperations: false

feign的重試

feign本身也具備重試能力,在早期的spring cloud中,feign使用的是 feign.retryer.default#default()  ,重試5次。但feign整合了ribbon,ribbon也有重試的能力,此時,就可能會導致行為的混亂。

spring cloud意識到了此問題,因此做了改進,將feign的重試改為 feign.retryer#never_retry  ,如需使用feign的重試,只需使用ribbon的重試配置即可。因此,對于camden以及以后的版本,feign的重試可使用如下屬性進行配置:

?
1
2
3
4
ribbon:
 maxautoretries: 1
 maxautoretriesnextserver: 2
 oktoretryonalloperations: false

相關issue可參考:https://github.com/spring-cloud/spring-cloud-netflix/issues/467

zuul的重試

配置:

?
1
2
3
4
5
6
7
zuul:
 # 開啟zuul的重試
 retryable: true
ribbon:
 maxautoretries: 1
 maxautoretriesnextserver: 2
 oktoretryonalloperations: false

上面我們使用 zuul.retryable=true 對zuul全局開啟了重試,事實上,也可對指定路由開啟/關閉重試:

?
1
zuul.routes.<routename>.retryable=true

局部配置優先級更高。

基于http響應碼重試

?
1
2
3
clientname:
 ribbon:
  retryablestatuscodes: 404,502

注意點:

hystrix的超時時間必須大于超時的時間,否則,一旦hystrix超時,就沒辦法繼續重試了。

一般來說,不建議將ribbon.oktoretryonalloperations 設為true。因為一旦啟用該配置,則表示重試任何操作,包括post請求,而由于緩存了請求體,此時可能會影響服務器的資源。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:http://www.itmuch.com/spring-cloud-sum/spring-cloud-retry/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国内精品一级毛片 | 一区二区在线影院 | 国产精品免费一区 | 精品国产999| 国产欧美日韩三级 | 免费看毛片的网站 | 四虎影院在线免费播放 | 欧美精品久久久久久久久老牛影院 | theporn国产在线精品 | 91综合在线观看 | 丝袜+亚洲+另类+欧美+变态 | 成人精品视频 | 欧美黄在线观看 | 一级片黄 | 中文在线一区二区三区 | 7799精品视频天天看 | 免费成人在线观看视频 | 凹凸国产成人精品视频免费 | 激情国产 | 看亚洲a级一级毛片 | 精品久久久网站 | 日韩在线一区二区 | 国产在线资源 | 欧美精品一区二区三区在线 | 国内精品视频在线观看 | 国产一区久久 | 久久精品久久综合 | 欧美日韩在线电影 | 特及毛片 | av片免费 | 欧美亚洲国产一区二区三区 | 欧美高潮 | 91精品国产综合久久香蕉922 | 国产一区二区精品久久岳 | 日韩欧美一区二区三区久久婷婷 | 久久精品国产一区二区电影 | 亚洲免费国产视频 | 亚洲国产成人精品女人久久久 | 精品96久久久久久中文字幕无 | 成人二区| 久久99精品久久久 |