0. 개요
2개의 서버가 LoadBalance(라운드 로빈)되는 설정
- localhost:8082,localhost:7777
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