-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/414 : Ai피드백 Resilence4j를 활용한 CB,Retry 적용 #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9e1197
feat:레질리언스4j 빌드그래들 설정
HeeMang-Lee 5e385ae
feat:레질리언스 appliciation properties 설정
HeeMang-Lee 000b232
feat:fallback구조 CB,Retry 데코레이터 패턴 적용
HeeMang-Lee ca531ba
chore:스트림 오류 매핑 적용 이후로 이동
HeeMang-Lee 0e236b0
chore:4xx 오류 집계 제외
HeeMang-Lee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
cs25-service/src/main/java/com/example/cs25service/domain/ai/resilience/AiResilience.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.example.cs25service.domain.ai.resilience; | ||
|
|
||
| import io.github.resilience4j.circuitbreaker.CircuitBreaker; | ||
| import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; | ||
| import io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator; | ||
| import io.github.resilience4j.reactor.retry.RetryOperator; | ||
| import io.github.resilience4j.retry.Retry; | ||
| import io.github.resilience4j.retry.RetryRegistry; | ||
| import java.util.function.Supplier; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
| import reactor.core.publisher.Flux; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AiResilience { | ||
|
|
||
| private final CircuitBreakerRegistry cbRegistry; | ||
| private final RetryRegistry retryRegistry; | ||
|
|
||
| /** | ||
| * 동기 호출: Retry → CircuitBreaker 순서 | ||
| */ | ||
| public <T> T executeSync(String name, Supplier<T> supplier) { | ||
| CircuitBreaker cb = cbRegistry.circuitBreaker(name); | ||
| Retry retry = retryRegistry.retry(name); | ||
|
|
||
| Supplier<T> withRetry = Retry.decorateSupplier(retry, supplier); | ||
| Supplier<T> withCb = CircuitBreaker.decorateSupplier(cb, withRetry); | ||
|
|
||
| return withCb.get(); | ||
| } | ||
|
|
||
| /** | ||
| * Flux 스트리밍: RetryOperator → CircuitBreakerOperator 순서 | ||
| */ | ||
| public <T> Flux<T> executeStream(String name, Supplier<Flux<T>> supplier) { | ||
| CircuitBreaker cb = cbRegistry.circuitBreaker(name); | ||
| Retry retry = retryRegistry.retry(name); | ||
|
|
||
| return supplier.get() | ||
| .transformDeferred(RetryOperator.of(retry)) | ||
| .transformDeferred(CircuitBreakerOperator.of(cb)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
4xx 클라이언트 오류는 Retry/CB 집계에서 제외하는 것을 강력 권장합니다.
현재 스트림 경로에서 오류가
AiException으로 래핑되어 올라오면 예외 타입 기반 필터링이 어려워집니다(아래 클라이언트 파일 코멘트의 리팩터를 먼저 적용 권장). 그 후 아래와 같이 4xx를 무시하도록 설정하면 불필요한 재시도/CB 오픈을 줄일 수 있습니다. 429(레이트리밋)는 유지해 재시도 대상으로 남기는 편이 좋습니다.아래 설정 추가를 제안드립니다(예: default config에 4xx 무시):
CircuitBreaker 쪽도 동일하게 4xx를 무시하도록 설정하면 더 안정적입니다.
참고: 이 설정이 효과를 내기 위해서는 아래 클라이언트 코드에서
onErrorResume로 즉시AiException을 던지던 부분을 Resilience4j 적용 “이후”로 이동해야 합니다(원인 유지).🤖 Prompt for AI Agents