Circuit Breaker
λ§μ΄ν¬λ‘μλΉμ€ κ° νΈμΆ μ€ν¨λ₯Ό κ°μ§νκ³ μμ€ν
μ₯μ μ νλ₯Ό μ°¨λ¨νλ ν¨ν΄
μ μ¬μ©νλμ§
μλΉμ€ κ° νΈμΆ μ€ν¨κ° μ°μμ μΌλ‘ λ°μνλ λ¬Έμ λ°©μ§
μΈλΆ API μ₯μ λ‘ μ 체 μμ€ν
λ€μ΄λλ μν© λ°©μ§
ν΄κ²°νλ λ¬Έμ
μ₯μ μ ν λ°©μ§
λΉ λ₯Έ μ€ν¨ μ²λ¦¬
μμ€ν μμ μ± ν보
Resilience4j
CircuitBreaker ꡬν λΌμ΄λΈλ¬λ¦¬
μ€ν¨μ¨ κΈ°λ° μν κ΄λ¦¬ λ° fallback μ 곡
Spring Cloud CircuitBreaker
μμ
β νΉμ§
π μ€μ λμ μν΄ κ΅¬ν체 νμ
νμ¬ νλ‘μ νΈ λ°©μ
implementation 'io.github.resilience4j:resilience4j-spring-boot3:2.2.0'
π μ΄μ
π μν νλ¦
Closed β Open β Half-Open β Closed
π μ€ν¨μ¨ κΈ°λ° μλ μ ν
@CircuitBreaker(name = "productService", fallbackMethod = "fallback")
public String call() {
return externalService.call();
}
public String fallback(Throwable t) {
return "fallback";
}
π μ₯μ μν©μμλ μλΉμ€ μ μ§ κ°λ₯
LLM (μ: GPT)
π λμ λ°©λ²
π LLM κ²°κ³Ό = μ°Έκ³ μ©
π μ€μ μ μ© μ κ²μ¦ νμ
Client β Service β External API
μ μ
Client β Service β External API β Success
μ₯μ λ°μ
Client β Service β External API β Fail
β μ€ν¨μ¨ μ¦κ°
β Circuit Open
μ΄ν
Client β Service β β External νΈμΆ μ°¨λ¨
β Fallback μ€ν
μμ² β μ€ν¨ λμ β μκ³κ° μ΄κ³Ό
β Open μν μ ν
β μΌμ μκ° ν Half-Open
β μ±κ³΅ μ Closed 볡κ·
dependencies {
implementation 'io.github.resilience4j:resilience4j-spring-boot3:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-aop'
}
@Service
public class ProductService {
@CircuitBreaker(name = "productService", fallbackMethod = "fallback")
public String getProduct(String id) {
if ("111".equals(id)) {
throw new RuntimeException("error");
}
return "product " + id;
}
public String fallback(String id, Throwable t) {
return "fallback product " + id;
}
}
resilience4j:
circuitbreaker:
configs:
default:
slidingWindowType: COUNT_BASED
slidingWindowSize: 5
minimumNumberOfCalls: 5
failureRateThreshold: 50
waitDurationInOpenState: 20s