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

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務(wù)器之家 - 編程語言 - JAVA教程 - 淺談Spring Cloud Ribbon的原理

淺談Spring Cloud Ribbon的原理

2021-04-06 11:37白色的海 JAVA教程

這篇文章主要介紹了淺談Spring Cloud Ribbon的原理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

ribbon是netflix發(fā)布的開源項目,主要功能是提供客戶端的軟件負(fù)載均衡算法,將netflix的中間層服務(wù)連接在一起。ribbon客戶端組件提供一系列完善的配置項如連接超時,重試等。簡單的說,就是在配置文件中列出load balancer(簡稱lb)后面所有的機(jī)器,ribbon會自動的幫助你基于某種規(guī)則(如簡單輪詢,隨即連接等)去連接這些機(jī)器。我們也很容易使用ribbon實(shí)現(xiàn)自定義的負(fù)載均衡算法。

說起負(fù)載均衡一般都會想到服務(wù)端的負(fù)載均衡,常用產(chǎn)品包括lbs硬件或云服務(wù)、nginx等,都是耳熟能詳?shù)漠a(chǎn)品。

而spring cloud提供了讓服務(wù)調(diào)用端具備負(fù)載均衡能力的ribbon,通過和eureka的緊密結(jié)合,不用在服務(wù)集群內(nèi)再架設(shè)負(fù)載均衡服務(wù),很大程度簡化了服務(wù)集群內(nèi)的架構(gòu)。

具體也不想多寫虛的介紹,反正哪里都能看得到相關(guān)的介紹。

直接開擼代碼,通過代碼來看ribbon是如何實(shí)現(xiàn)的。

配置

淺談Spring Cloud Ribbon的原理

詳解:

1.ribbonautoconfiguration配置生成ribbonloadbalancerclient實(shí)例。

代碼位置:

spring-cloud-netflix-core-1.3.5.release.jar

org.springframework.cloud.netflix.ribbon

ribbonautoconfiguration.class

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@configuration
@conditionalonclass({ iclient.class, resttemplate.class, asyncresttemplate.class, ribbon.class})
@ribbonclients
@autoconfigureafter(name = "org.springframework.cloud.netflix.eureka.eurekaclientautoconfiguration")
@autoconfigurebefore({loadbalancerautoconfiguration.class, asyncloadbalancerautoconfiguration.class})
@enableconfigurationproperties(ribboneagerloadproperties.class)
public class ribbonautoconfiguration {
 
 // 略
 
 @bean
 @conditionalonmissingbean(loadbalancerclient.class)
 public loadbalancerclient loadbalancerclient() {
  return new ribbonloadbalancerclient(springclientfactory());
 }
  // 略
}

先看配置條件項,ribbonautoconfiguration配置必須在loadbalancerautoconfiguration配置前執(zhí)行,因為在loadbalancerautoconfiguration配置中會使用ribbonloadbalancerclient實(shí)例。

ribbonloadbalancerclient繼承自loadbalancerclient接口,是負(fù)載均衡客戶端,也是負(fù)載均衡策略的調(diào)用方。

2.loadbalancerinterceptorconfig配置生成:

1).負(fù)載均衡攔截器loadbalancerinterceptor實(shí)例

包含:

loadbalancerclient實(shí)現(xiàn)類的ribbonloadbalancerclient實(shí)例

負(fù)載均衡的請求創(chuàng)建工廠loadbalancerrequestfactory:實(shí)例

2).resttemplate自定義的resttemplatecustomizer實(shí)例

代碼位置:

spring-cloud-commons-1.2.4.release.jar

org.springframework.cloud.client.loadbalancer

loadbalancerautoconfiguration.class

?
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
36
37
38
39
40
@configuration
@conditionalonclass(resttemplate.class)
@conditionalonbean(loadbalancerclient.class)
@enableconfigurationproperties(loadbalancerretryproperties.class)
public class loadbalancerautoconfiguration {
 // 略
 @bean
 @conditionalonmissingbean
 public loadbalancerrequestfactory loadbalancerrequestfactory(
   loadbalancerclient loadbalancerclient) {
  return new loadbalancerrequestfactory(loadbalancerclient, transformers);
 }
 
 @configuration
 @conditionalonmissingclass("org.springframework.retry.support.retrytemplate")
 static class loadbalancerinterceptorconfig {
  @bean
  public loadbalancerinterceptor ribboninterceptor(
    loadbalancerclient loadbalancerclient,
    loadbalancerrequestfactory requestfactory) {
   return new loadbalancerinterceptor(loadbalancerclient, requestfactory);
  }
 
  @bean
  @conditionalonmissingbean
  public resttemplatecustomizer resttemplatecustomizer(
    final loadbalancerinterceptor loadbalancerinterceptor) {
   return new resttemplatecustomizer() {
    @override
    public void customize(resttemplate resttemplate) {
     list<clienthttprequestinterceptor> list = new arraylist<>(
       resttemplate.getinterceptors());
     list.add(loadbalancerinterceptor);
     resttemplate.setinterceptors(list);
    }
   };
  }
 }
 // 略
}

先看配置條件項:

要求在項目環(huán)境中必須要有resttemplate類。

要求必須要有l(wèi)oadbalancerclient接口的實(shí)現(xiàn)類的實(shí)例,也就是上一步生成的ribbonloadbalancerclient。

3.通過上面一步創(chuàng)建的resttemplatecustomizer配置所有resttemplate實(shí)例,就是將負(fù)載均衡攔截器設(shè)置給resttemplate實(shí)例。

?
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@configuration
@conditionalonclass(resttemplate.class)
@conditionalonbean(loadbalancerclient.class)
@enableconfigurationproperties(loadbalancerretryproperties.class)
public class loadbalancerautoconfiguration {
 // 略
 
 @bean
 public smartinitializingsingleton loadbalancedresttemplateinitializer(
   final list<resttemplatecustomizer> customizers) {
  return new smartinitializingsingleton() {
   @override
   public void aftersingletonsinstantiated() {
    for (resttemplate resttemplate : loadbalancerautoconfiguration.this.resttemplates) {
     for (resttemplatecustomizer customizer : customizers) {
      customizer.customize(resttemplate);
     }
    }
   }
  };
 }
 
 // 略
 @configuration
 @conditionalonmissingclass("org.springframework.retry.support.retrytemplate")
 static class loadbalancerinterceptorconfig {
  @bean
  public loadbalancerinterceptor ribboninterceptor(
    loadbalancerclient loadbalancerclient,
    loadbalancerrequestfactory requestfactory) {
   return new loadbalancerinterceptor(loadbalancerclient, requestfactory);
  }
 
  @bean
  @conditionalonmissingbean
  public resttemplatecustomizer resttemplatecustomizer(
    final loadbalancerinterceptor loadbalancerinterceptor) {
   return new resttemplatecustomizer() {
    @override
    public void customize(resttemplate resttemplate) {
     list<clienthttprequestinterceptor> list = new arraylist<>(
       resttemplate.getinterceptors());
     list.add(loadbalancerinterceptor);
     resttemplate.setinterceptors(list);
    }
   };
  }
 }
 // 略
}

resttemplate.setinterceptors(list)這個地方就是注入負(fù)載均衡攔截器的地方loadbalancerinterceptor。

從這個地方實(shí)際上也可以猜出來,resttemplate可以通過注入的攔截器來構(gòu)建相應(yīng)的請求實(shí)現(xiàn)負(fù)載均衡。

也能看出來可以自定義攔截器實(shí)現(xiàn)其他目的。

4.ribbonclientconfiguration配置生成zoneawareloadbalancer實(shí)例

代碼位置:

spring-cloud-netflix-core-1.3.5.release.jar

org.springframework.cloud.netflix.ribbon

ribbonclientconfiguration.class

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@suppresswarnings("deprecation")
@configuration
@enableconfigurationproperties
//order is important here, last should be the default, first should be optional
// see https://github.com/spring-cloud/spring-cloud-netflix/issues/2086#issuecomment-316281653
@import({okhttpribbonconfiguration.class, restclientribbonconfiguration.class, httpclientribbonconfiguration.class})
public class ribbonclientconfiguration {
 // 略
 @bean
 @conditionalonmissingbean
 public iloadbalancer ribbonloadbalancer(iclientconfig config,
   serverlist<server> serverlist, serverlistfilter<server> serverlistfilter,
   irule rule, iping ping, serverlistupdater serverlistupdater) {
  if (this.propertiesfactory.isset(iloadbalancer.class, name)) {
   return this.propertiesfactory.get(iloadbalancer.class, config, name);
  }
  return new zoneawareloadbalancer<>(config, rule, ping, serverlist,
    serverlistfilter, serverlistupdater);
 }
 
 // 略
}

zoneawareloadbalancer繼承自iloadbalancer接口,該接口有一個方法:

?
1
2
3
4
5
6
7
8
/**
 * choose a server from load balancer.
 *
 * @param key an object that the load balancer may use to determine which server to return. null if
 *   the load balancer does not use this parameter.
 * @return server chosen
 */
public server chooseserver(object key);

zoneawareloadbalancer就是一個具體的負(fù)載均衡實(shí)現(xiàn)類,也是默認(rèn)的負(fù)載均衡類,通過對chooseserver方法的實(shí)現(xiàn)選取某個服務(wù)實(shí)例。

攔截&請求

淺談Spring Cloud Ribbon的原理

1.使用resttemplate進(jìn)行g(shù)et、post等各種請求,都是通過doexecute方法實(shí)現(xiàn)

代碼位置:
spring-web-4.3.12.release.jar

org.springframework.web.client

resttemplate.class

?
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
36
37
38
39
40
41
public class resttemplate extends interceptinghttpaccessor implements restoperations {
 
 // 略
 
 protected <t> t doexecute(uri url, httpmethod method, requestcallback requestcallback,
   responseextractor<t> responseextractor) throws restclientexception {
 
  assert.notnull(url, "'url' must not be null");
  assert.notnull(method, "'method' must not be null");
  clienthttpresponse response = null;
  try {
   clienthttprequest request = createrequest(url, method);
   if (requestcallback != null) {
    requestcallback.dowithrequest(request);
   }
   response = request.execute();
   handleresponse(url, method, response);
   if (responseextractor != null) {
    return responseextractor.extractdata(response);
   }
   else {
    return null;
   }
  }
  catch (ioexception ex) {
   string resource = url.tostring();
   string query = url.getrawquery();
   resource = (query != null ? resource.substring(0, resource.indexof('?')) : resource);
   throw new resourceaccessexception("i/o error on " + method.name() +
     " request for \"" + resource + "\": " + ex.getmessage(), ex);
  }
  finally {
   if (response != null) {
    response.close();
   }
  }
 }
 
 // 略
 
}

支持的各種http請求方法最終都是調(diào)用doexecute方法,該方法內(nèi)調(diào)用創(chuàng)建方法創(chuàng)建請求實(shí)例,并執(zhí)行請求得到響應(yīng)對象。

2.生成請求實(shí)例創(chuàng)建工廠

上一步代碼中,調(diào)用createrequest方法創(chuàng)建請求實(shí)例,這個方法是定義在父類中。

先整理出主要的繼承關(guān)系:

淺談Spring Cloud Ribbon的原理

createrequest方法實(shí)際是定義在httpaccessor抽象類中。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public abstract class httpaccessor {
 private clienthttprequestfactory requestfactory = new simpleclienthttprequestfactory();
 public void setrequestfactory(clienthttprequestfactory requestfactory) {
  assert.notnull(requestfactory, "clienthttprequestfactory must not be null");
  this.requestfactory = requestfactory;
 }
 public clienthttprequestfactory getrequestfactory() {
  return this.requestfactory;
 }
 protected clienthttprequest createrequest(uri url, httpmethod method) throws ioexception {
  clienthttprequest request = getrequestfactory().createrequest(url, method);
  if (logger.isdebugenabled()) {
   logger.debug("created " + method.name() + " request for \"" + url + "\"");
  }
  return request;
 }
}

在createrequest方法中調(diào)用getrequestfactory方法獲得請求實(shí)例創(chuàng)建工廠,實(shí)際上getrequestfactory并不是當(dāng)前httpaccessor類中定義的,而是在子類interceptinghttpaccessor中定義的。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public abstract class interceptinghttpaccessor extends httpaccessor {
 
 private list<clienthttprequestinterceptor> interceptors = new arraylist<clienthttprequestinterceptor>();
 
 public void setinterceptors(list<clienthttprequestinterceptor> interceptors) {
  this.interceptors = interceptors;
 }
 
 public list<clienthttprequestinterceptor> getinterceptors() {
  return interceptors;
 }
 
 @override
 public clienthttprequestfactory getrequestfactory() {
  clienthttprequestfactory delegate = super.getrequestfactory();
  if (!collectionutils.isempty(getinterceptors())) {
   return new interceptingclienthttprequestfactory(delegate, getinterceptors());
  }
  else {
   return delegate;
  }
 }
}

在這里做了個小動作,首先還是通過httpaccessor類創(chuàng)建并獲得simpleclienthttprequestfactory工廠,這個工廠主要就是在沒有攔截器的時候創(chuàng)建基本請求實(shí)例。

其次,在有攔截器注入的情況下,創(chuàng)建interceptingclienthttprequestfactory工廠,該工廠就是創(chuàng)建帶攔截器的請求實(shí)例,因為注入了負(fù)載均衡攔截器,所以這里就從interceptingclienthttprequestfactory工廠創(chuàng)建。

3.通過工廠創(chuàng)建請求實(shí)例

創(chuàng)建實(shí)例就看工廠的createrequest方法。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class interceptingclienthttprequestfactory extends abstractclienthttprequestfactorywrapper {
 
 private final list<clienthttprequestinterceptor> interceptors;
 
 public interceptingclienthttprequestfactory(clienthttprequestfactory requestfactory,
   list<clienthttprequestinterceptor> interceptors) {
 
  super(requestfactory);
  this.interceptors = (interceptors != null ? interceptors : collections.<clienthttprequestinterceptor>emptylist());
 }
 
 
 @override
 protected clienthttprequest createrequest(uri uri, httpmethod httpmethod, clienthttprequestfactory requestfactory) {
  return new interceptingclienthttprequest(requestfactory, this.interceptors, uri, httpmethod);
 }
 
}

就是new了個interceptingclienthttprequest實(shí)例,并且把攔截器、基本請求實(shí)例創(chuàng)建工廠注進(jìn)去。

4.請求實(shí)例調(diào)用配置階段注入的負(fù)載均衡攔截器的攔截方法intercept

可從第1步看出,創(chuàng)建完請求實(shí)例后,通過執(zhí)行請求實(shí)例的execute方法執(zhí)行請求。

?
1
2
3
4
5
clienthttprequest request = createrequest(url, method);
if (requestcallback != null) {
 requestcallback.dowithrequest(request);
}
response = request.execute();

實(shí)際請求實(shí)例是interceptingclienthttprequest,execute實(shí)際是在它的父類中。

類定義位置:

spring-web-4.3.12.release.jar

org.springframework.http.client

interceptingclienthttprequest.class

看一下它們的繼承關(guān)系。

淺談Spring Cloud Ribbon的原理

在execute方法中實(shí)際調(diào)用了子類實(shí)現(xiàn)的executeinternal方法。

?
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
public abstract class abstractclienthttprequest implements clienthttprequest {
 
 private final httpheaders headers = new httpheaders();
 
 private boolean executed = false;
 
 @override
 public final httpheaders getheaders() {
  return (this.executed ? httpheaders.readonlyhttpheaders(this.headers) : this.headers);
 }
 
 @override
 public final outputstream getbody() throws ioexception {
  assertnotexecuted();
  return getbodyinternal(this.headers);
 }
 
 @override
 public final clienthttpresponse execute() throws ioexception {
  assertnotexecuted();
  clienthttpresponse result = executeinternal(this.headers);
  this.executed = true;
  return result;
 }
 
 protected void assertnotexecuted() {
  assert.state(!this.executed, "clienthttprequest already executed");
 }
 
 protected abstract outputstream getbodyinternal(httpheaders headers) throws ioexception;
 
 protected abstract clienthttpresponse executeinternal(httpheaders headers) throws ioexception;
 
}

其實(shí)就是interceptingclienthttprequest類的executeinternal方法,其中,又調(diào)用了一個執(zhí)行器interceptingrequestexecution的execute,通關(guān)判斷如果有攔截器注入進(jìn)來過,就調(diào)用攔截器的intercept方法。

這里的攔截器實(shí)際上就是在配置階段注入進(jìn)resttemplate實(shí)例的負(fù)載均衡攔截器loadbalancerinterceptor實(shí)例,可參考上面配置階段的第2步。

?
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
36
37
38
39
40
41
42
class interceptingclienthttprequest extends abstractbufferingclienthttprequest {
 
 // 略
 
 @override
 protected final clienthttpresponse executeinternal(httpheaders headers, byte[] bufferedoutput) throws ioexception {
  interceptingrequestexecution requestexecution = new interceptingrequestexecution();
  return requestexecution.execute(this, bufferedoutput);
 }
 
 
 private class interceptingrequestexecution implements clienthttprequestexecution {
 
  private final iterator<clienthttprequestinterceptor> iterator;
 
  public interceptingrequestexecution() {
   this.iterator = interceptors.iterator();
  }
 
  @override
  public clienthttpresponse execute(httprequest request, byte[] body) throws ioexception {
   if (this.iterator.hasnext()) {
    clienthttprequestinterceptor nextinterceptor = this.iterator.next();
    return nextinterceptor.intercept(request, body, this);
   }
   else {
    clienthttprequest delegate = requestfactory.createrequest(request.geturi(), request.getmethod());
    for (map.entry<string, list<string>> entry : request.getheaders().entryset()) {
     list<string> values = entry.getvalue();
     for (string value : values) {
      delegate.getheaders().add(entry.getkey(), value);
     }
    }
    if (body.length > 0) {
     streamutils.copy(body, delegate.getbody());
    }
    return delegate.execute();
   }
  }
 }
 
}

5.負(fù)載均衡攔截器調(diào)用負(fù)載均衡客戶端

在負(fù)載均衡攔截器loadbalancerinterceptor類的intercept方法中,又調(diào)用了負(fù)載均衡客戶端loadbalancerclient實(shí)現(xiàn)類的execute方法。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class loadbalancerinterceptor implements clienthttprequestinterceptor {
 
 private loadbalancerclient loadbalancer;
 private loadbalancerrequestfactory requestfactory;
 
 public loadbalancerinterceptor(loadbalancerclient loadbalancer, loadbalancerrequestfactory requestfactory) {
  this.loadbalancer = loadbalancer;
  this.requestfactory = requestfactory;
 }
 
 public loadbalancerinterceptor(loadbalancerclient loadbalancer) {
  // for backwards compatibility
  this(loadbalancer, new loadbalancerrequestfactory(loadbalancer));
 }
 
 @override
 public clienthttpresponse intercept(final httprequest request, final byte[] body,
   final clienthttprequestexecution execution) throws ioexception {
  final uri originaluri = request.geturi();
  string servicename = originaluri.gethost();
  assert.state(servicename != null, "request uri does not contain a valid hostname: " + originaluri);
  return this.loadbalancer.execute(servicename, requestfactory.createrequest(request, body, execution));
 }
}

在配置階段的第1步,可以看到實(shí)現(xiàn)類是ribbonloadbalancerclient。

6.負(fù)載均衡客戶端調(diào)用負(fù)載均衡策略選取目標(biāo)服務(wù)實(shí)例并發(fā)起請求

在ribbonloadbalancerclient的第一個execute方法以及getserver方法中可以看到,實(shí)際上是通過iloadbalancer的負(fù)載均衡器實(shí)現(xiàn)類作的chooseserver方法選取一個服務(wù),交給接下來的請求對象發(fā)起一個請求。

這里的負(fù)載均衡實(shí)現(xiàn)類默認(rèn)是zoneawareloadbalancer區(qū)域感知負(fù)載均衡器實(shí)例,其內(nèi)部通過均衡策略選擇一個服務(wù)。

zoneawareloadbalancer的創(chuàng)建可以參考配置階段的第4步。

?
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
public class ribbonloadbalancerclient implements loadbalancerclient {
 @override
 public <t> t execute(string serviceid, loadbalancerrequest<t> request) throws ioexception {
  iloadbalancer loadbalancer = getloadbalancer(serviceid);
  server server = getserver(loadbalancer);
  if (server == null) {
   throw new illegalstateexception("no instances available for " + serviceid);
  }
  ribbonserver ribbonserver = new ribbonserver(serviceid, server, issecure(server,
    serviceid), serverintrospector(serviceid).getmetadata(server));
 
  return execute(serviceid, ribbonserver, request);
 }
 
 @override
 public <t> t execute(string serviceid, serviceinstance serviceinstance, loadbalancerrequest<t> request) throws ioexception {
  server server = null;
  if(serviceinstance instanceof ribbonserver) {
   server = ((ribbonserver)serviceinstance).getserver();
  }
  if (server == null) {
   throw new illegalstateexception("no instances available for " + serviceid);
  }
 
  ribbonloadbalancercontext context = this.clientfactory
    .getloadbalancercontext(serviceid);
  ribbonstatsrecorder statsrecorder = new ribbonstatsrecorder(context, server);
 
  try {
   t returnval = request.apply(serviceinstance);
   statsrecorder.recordstats(returnval);
   return returnval;
  }
  // catch ioexception and rethrow so resttemplate behaves correctly
  catch (ioexception ex) {
   statsrecorder.recordstats(ex);
   throw ex;
  }
  catch (exception ex) {
   statsrecorder.recordstats(ex);
   reflectionutils.rethrowruntimeexception(ex);
  }
  return null;
 }
  
 // 略
 
 protected server getserver(iloadbalancer loadbalancer) {
  if (loadbalancer == null) {
   return null;
  }
  return loadbalancer.chooseserver("default"); // todo: better handling of key
 }
 
 protected iloadbalancer getloadbalancer(string serviceid) {
  return this.clientfactory.getloadbalancer(serviceid);
 }
 
 public static class ribbonserver implements serviceinstance {
  private final string serviceid;
  private final server server;
  private final boolean secure;
  private map<string, string> metadata;
 
  public ribbonserver(string serviceid, server server) {
   this(serviceid, server, false, collections.<string, string> emptymap());
  }
 
  public ribbonserver(string serviceid, server server, boolean secure,
    map<string, string> metadata) {
   this.serviceid = serviceid;
   this.server = server;
   this.secure = secure;
   this.metadata = metadata;
  }
 
  // 略
 }
 
}

代碼擼完,總結(jié)下。

普通使用resttemplate請求其他服務(wù)時,內(nèi)部使用的就是常規(guī)的http請求實(shí)例發(fā)送請求。

為resttemplate增加了@loanbalanced 注解后,實(shí)際上通過配置,為resttemplate注入負(fù)載均衡攔截器,讓負(fù)載均衡器選擇根據(jù)其對應(yīng)的策略選擇合適的服務(wù)后,再發(fā)送請求。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://www.cnblogs.com/kongxianghai/p/8445030.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 手机黄网www8xcn | 国产精品爱久久久久久久 | 免费观看黄色大片 | 国产免费一区二区三区 | 北条麻妃99精品青青久久 | 夜夜夜久久久 | 99精品网站| 久久久国产一区 | 国产成人精品午夜视频' | 欧美精品久久久 | 欧美在线观看www | 亚洲精品免费看 | 狠狠爱亚洲| 伦理午夜电影免费观看 | 国产日韩精品一区二区 | 91大神免费观看 | 亚洲视频一区二区三区 | 国产精品美女久久久久久久网站 | 日韩精品在线播放 | 欧美日韩激情 | 黄色小视频在线观看 | 一本色道久久综合狠狠躁篇的优点 | 亚洲国产精品美女 | 欧美日韩专区 | www.国产区 | 免费看a| 久久综合久| 久草成人网 | 久久精品免费一区二区三区 | 欧美一级在线 | 毛片网站大全 | 最新国产一区二区 | 无码一区二区三区视频 | 国产精品美女久久久久aⅴ国产馆 | 亚洲网站免费 | 天堂久久精品 | 久久久久一区二区三区 | 黄色一级毛片免费看 | 国产日产精品一区二区三区四区 | 亚洲aⅴ网站 | 成人激情在线播放 |