-
Notifications
You must be signed in to change notification settings - Fork 1
[Refactor] 보험 추천 리포트 발급 실패 처리 개선 #211
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
Conversation
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
- NewImageRequest 는 현재 사용하고 있지 않지만, 추후 다시 사용하게 될 경우를 대비하여 함께 수정함
- 빈으로 사용하도록 함. ObjectMapper의 설정을 공통되게 사용할 수 있도록 하기 위함
- 기존에 불필요하게 높았던 결합도를 낮추고자 GenerateAiClient 를 도입하여 OpenAiClient 를 감춤
- 메세지 큐를 목적 단위로 나누고자 함. 따라서 GenerativeAi 요청을 위한 메세지 큐를 둠
- 메세지 큐를 목적 단위로 나누고자 함. 따라서 GenerativeAi 요청을 위한 메세지 큐를 둠
- 모든 MessageBroker는 메세지 발급이 가능해야하므로 MessagePublisher 를 상속 받음
- 내부의 MessageStrategyProvider 를 통해 요청 메세지에 맞는 알맞은 strategy 를 판단해 메세지를 발급함
- api 에서만 폴백 로직을 처리하기 위함
- 스케줄러가 SQS 메세지 발급을 누락없이 확정적으로 처리하도록 하기 위함
- 리포트 생성 이후 메세지 발급과 outboxMessage 를 생성하므로 로직 흐름상 일관성이 향상됨. message 나 outboxMessage 만 존재하고 report가 없는 경우가 존재하지 않음
- 누락된 SQS 메세지가 존재할 경우 동기적으로 SQS 큐에 메세지를 전달함
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related issue 🛠
Work Description 📝
메시지 브로커 아키텍처 구현 (Strategy Pattern)
MessageBrokerResolver,MessageStrategyProvider,MessageBrokerStrategy를 구현하여 메시지 타입에 따라 적절한 브로커(현재는 SQS)가 선택되도록 전략 패턴을 사용함Message,MessageHandler인터페이스를 정의하여 메시지 생성과 처리 로직을 분리JsonMapper를 빈으로 등록하여 직렬화/역직렬화 설정을 통일. (아직 별도의 설정은 없음.)AWS SQS
SqsStrategy,GenerativeAiSqsStrategy구현.SqsListenerStarter를 통해 애플리케이션 시작 시 리스너가 동작하도록 설정.GenerativeAiSqsStrategy에선 처리 실패 시 애플리케이션 레벨에서 점진적으로 재시도 간격을 늘리도록 설정함.Transactional Outbox Pattern 적용
OutboxMessage엔티티 및 Repository: 발행할 메시지를 DB에 먼저 저장하여 비즈니스 트랜잭션과의 원자성 보장.OutboxMessageScheduler: 발송 누락된 메시지(lastAttemptAt이 없는 OutboxMessagfe)를 주기적으로 탐색하여 재발송함.Circuit Breaker 도입
리팩토링
GenerateAiClient인터페이스 도입:OpenAiClient의 결합도를 낮추고, API 호출용과 메시지 큐 처리용 로직을 분리함.기술 고민
왜 SQS 를 사용했는가?
왜 Outbox Pattern을 도입했는가?
처음엔 기본적으로 메세지 발급을 모두 비동기적으로 처리하고 있었으므로 스케줄러는 LastAttemptAt 이 null이면 메세지 발급, 이후 폴링해서 LastAttemptAt 을 업데이트 하는 플로우를 생각했음.(LastAttemptAt 갱신 == SQS 에 메세지가 들어갔는지 판단하는 부분을 수신하는 쪽에서 처리한다는 것.) 다만 이렇게 수신하는 쪽에서 처리는 경우 메세지 큐가 많이 밀렸을 때 앞의 메세지가 처리되지 못해서 계속해서 대기중일 수 있고, 이 경우 송신하는 스케줄러는 계속 해당 메세지가 큐에 들어가지 않았다고 판단해서 지연 중인 메세지 큐에 요청을 계속 다시 보내 상황을 악화시킬 수 있음. 따라서 메세지를 큐에 동기적으로 전송하는 메서드를 별도로 두어 실패 시 LastAttemptAt 을 업데이트하지 않아 다음 스케줄러에서 다시 전송을 시도하도록 함.
Circuit Breaker 도입에 대한 고민
Uncompleted Tasks 😅
To Reviewers 📢