Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
  • 2개의 서버가 LoadBalance(라운드 로빈)되는 설정
    • localhost:8082,localhost:7777
  • localhost:7777은 없는 주소 이므로 Exception 발생. 그러나 Ribbon Retry로 항상 성공
    • Round Robin Client Load Balancing & Retry.


01. RestTemplate에 Ribbon 적용하기

Code Block
git checkout tags/step-3-ribbon-loadbalancedretry -b step-3-ribbon-loadbalancedretry

1. [display] build.gradle에 dependency 추가

Code Block
compile('org.springframework.cloud:spring-cloud-starter-netflix-ribbon')
compile('org.springframework.retry:spring-retry:1.2.2.RELEASE')

2. [display] DisplayApplication의 RestTemplate 빈에 @LoadBalanced 추가

Code Block
@LoadBalanced
public RestTemplate restTemplate() {
    return new RestTemplate();
}

3. [display] ProductRemoteServiceImpl에서 주소 제거하고 `product` 로 변경

Code Block
public class ProductRemoteServiceImpl implements ProductRemoteService {

	//private static final String url = "http://localhost:8082/products/";
    private static final String url = "http://product/products/";
    private final RestTemplate restTemplate;
}

4. [display] application.yml에 ribbon 설정 넣기

Code Block
product:
  ribbon:
    listOfServers: localhost:8082,localhost:7777
    MaxAutoRetries: 0
    MaxAutoRetriesNextServer: 1


5. 실행결과

Info

Image Added

Image Added

Code Block
2020-02-25 17:01:46.374  INFO 57352 --- [teServiceImpl-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client product initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=product,current list of Servers=[localhost:8082, localhost:7777],Load balancer stats=Zone stats: {unknown=[Zone:unknown;	Instance count:2;	Active connections count: 0;	Circuit breaker tripped count: 0;	Active connections per server: 0.0;]
},Server stats: [[Server:localhost:7777;	Zone:UNKNOWN;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 09:00:00 KST 1970;	First connection made: Thu Jan 01 09:00:00 KST 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]
, [Server:localhost:8082;	Zone:UNKNOWN;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 09:00:00 KST 1970;	First connection made: Thu Jan 01 09:00:00 KST 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:com.netflix.loadbalancer.ConfigurationBasedServerList@2b94e297
2020-02-25 17:01:47.303  INFO 57352 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty  : Flipping property: product.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647