Versions Compared

Key

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

Table of Contents

0. 개요

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
product:
  ribbon:
    listOfServers: localhost:80827777, localhost:77778082
    MaxAutoRetries: 0
    MaxAutoRetriesNextServer: 1


5. 실행결과

Info

Image Added

Image Added

Code Block
2020-02-25 17:06:30.875  INFO 79048 --- [teServiceImpl-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client product initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=product,current list of Servers=[localhost:7777, localhost:8082],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@5d174c88
2020-02-25 17:06:31.823  INFO 79048 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty  : Flipping property: product.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647

6. 정리

Info

- Ribbon은 여러 Component에 내장되어있으며, 이를 통해 Client Load Balancing이 수행 가능하다.
- Ribbon에는 매우 다양한 설정이 가능하다 (서버선택, 실패시 Skip 시간, Ping 체크)
- Ribbon에는 Retry기능이 내장 되어있다.
- Eureka와 함께 사용될 때 강력하다 (뒤에 실습)