Closed yanghun0070 closed 4 years ago
정상 여부를 확인하기 위해서는 주기적으로 아래 클래스를 통해 new PingUrl(false, "/actuator/health")
에 핑을 보내게 되는데, 해당 url 없기 때문에 에러나는 현상 이므로, spring boot에서 제공되는 actuator url 로 변경 진행
@RibbonClients(defaultConfiguration = RibbonConfiguration.class)
구현 이유? 문제의 원인은 리본은 라운드 로빈 전략으로 구성되고, 상태 체크 메커니즘을 none 으로 설정되어 있습니다. 그러므로, 로드벨런스에서 서비스가 살아있는 지 알 수 없습니다. 유레카가 인스턴스를 등록하고 해지 시키는 시간도 평균 3분 정도 걸립니다. (leaseRenewalIntervalInSeconds
매개변수를 수정하는 것은 좋지않음 ) 리본에defaultConfiguration
을 설정해, 서비스에 핑을 보내고 결과에 따라, 로드벨런싱하는 기능을 추가했습니다. 로드밸런싱 할때 대상 서버의 상태를 확인하고 정상인 경우에만 요청을 보내야 합니다.
public class RibbonConfiguration {
/**
* Returns the {@link IPing} changes the default state checking mechanism
*
* @param config the {@link IClientConfig}
*/
@Bean
public IPing ribbonPing(final IClientConfig config) {
return new PingUrl(false, "/actuator/health");
}
/**
* Returns the {@link IRule} to modify default load balancing strategy
*
* @param config the {@link IClientConfig}
*/
@Bean
public IRule ribbonRule(final IClientConfig config) {
return new AvailabilityFilteringRule();
}
}
LoadBalancer [hello]: Error choosing server for key null 에러