You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

0. 개요

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


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

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

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

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

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

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 설정 넣기

product:
  ribbon:
    listOfServers: localhost:8082,localhost:7777
    MaxAutoRetries: 0
    MaxAutoRetriesNextServer: 1
  • No labels