CNCF의 Graduated 프로젝트인 Istio(Service Mesh)를 주로 Circuit Breaker 용도로 쓰다보니 Hystrix 같은 다소 Application 영역에 대한 궁금증이 생겼다. 얼마 전 Eureka&OpenFeign 관련 구현을 할 때 Hystrix 대신 Resilience4J가 활용되기 시작하는 것을 보았는데, 환경을 간단히 구성하고 테스트해보기로 한다.
실행 환경 구성
Spring Cloud Circuit Breaker 샘플 프로젝트는 SpringBoot 2를 기반으로 되어있는데, 관련된 설정을 일부 변경하여 진행.
[참고] https://github.com/spring-cloud-samples/spring-cloud-circuitbreaker-demo
GitHub - spring-cloud-samples/spring-cloud-circuitbreaker-demo: Samples demonstrating how to using Spring Cloud Circuitbreaker
Samples demonstrating how to using Spring Cloud Circuitbreaker - spring-cloud-samples/spring-cloud-circuitbreaker-demo
github.com
Trouble Shooting
CircuitBreakerFactory 호환 문제
테스트를 하려다보니 spring-boot-starter-parent 3.1.x는 정상적으로 호환이 되지 않는 것으로 보여진다. 아래 Guide를 참고하여 기존 2.5.8에서 3.0.2로 변경 후, 서비스가 정상적으로 기동되었다.
[참고] https://spring.io/guides/gs/cloud-circuit-breaker
Getting Started | Spring Cloud Circuit Breaker Guide
Spring Cloud’s Circuit Breaker library provides an implementation of the Circuit Breaker pattern: When we wrap a method call in a circuit breaker, Spring Cloud Circuit Breaker watches for failing calls to that method and, if failures build up to a specif
spring.io
httpbin.org 호출시 SSL 오류
Local 환경에서 테스트하는 과정에 unable to find valid certification path to requested target 오류가 발생되었다. 브라우저를 통한 인증서(httpbin.org.cer) 내보내기 후, keytool 도구를 활용하여 아래와 같이 수행하면 해결 가능하다. (초기 패스워드: changeit)
➜ ~ keytool -import -keystore "$JAVA_HOME/lib/security/cacerts" -file "httpbin.org.cer" -alias "httpbin"
Warning: use -cacerts option to access cacerts keystore
Enter keystore password:
..생략..
Trust this certificate? [no]: yes
Certificate was added to keystore
테스트
repository 에 있는 grafana 폴더의 docker-compose.yml을 이용하여 Grafana와 Prometheus를 아래와 같이 준비한다.
➜ grafana (main) ✗ docker-compose up
[+] Running 2/0
✔ Container grafana-grafana-1 Running 0.0s
✔ Container grafana-prometheus-1 Running 0.0s
Attaching to grafana-grafana-1, grafana-prometheus-1
이 후, Resilience4JCircuitbreakerDemoApplication을 기동하여 아래와 같은 패턴의 호출을 반복시켰다.
호출 화면 | 설명 |
![]() |
단순히 /get을 호출하면 httpbin.org의 get method 출력 |
![]() |
3초 이하의 지연 호출을 하면 httpbin.org로 호출 전달 |
![]() |
3초 이상의 지연 호출을 하면 Circuit Breaker가 동작하여 내부적으로 Hello World를 출력. |
결과(w/Grafana)
대시보드의 resilience4j_circuitbreaker_calls_seconds_max 패널을 보면 Request 수행 시간이 3초 경과할 때 Circuit Breaker가 동작하여 추가적인 호출 지연이 발생되지 않는 것을 확인할 수 있다.
'Software > Spring Cloud' 카테고리의 다른 글
Spring Cloud Config 구성하기 (0) | 2024.04.05 |
---|---|
Spring Cloud Gateway를 Docker 환경에서 실행하기 (0) | 2024.03.29 |
Spring Cloud Eureka&OpenFeign Docker로 구성하기 (0) | 2024.03.27 |