Skip to content

Feat webclient timeout retry#17

Merged
JaesungGo merged 14 commits intomainfrom
feat-webclient-timeout-retry
Jun 19, 2025
Merged

Feat webclient timeout retry#17
JaesungGo merged 14 commits intomainfrom
feat-webclient-timeout-retry

Conversation

@JaesungGo
Copy link
Owner

✨ 이벤트 기반 비동기 외부 호출 구현

🔎 PR 개요

웹훅 처리 과정에서 외부 서비스 호출을 이벤트 기반 비동기 처리로 분리하여 시스템 안정성과 성능을 개선했습니다. ApplicationEventPublisher를 활용하여 PG 서버 상태 저장 후 가맹점 알림을 비동기로 처리하도록 변경했습니다.

@transactional 내부에서 결제 처리 완료 후 이벤트를 발행하고, 트랜잭션 커밋 후 비동기로 외부 호출을 수행하여 DB 무결성과 외부 호출을 분리했습니다. 또한 Spring이 제공하는 표준 재시도 매커니즘(@recover)를 활용하였습니다.

🔗 연관된 이슈

🔧 주요 변경 사항

  • 이벤트 기반 외부 호출 구현: ApplicationEventPublisher를 통한 가맹점 알림 비동기 처리
  • PaymentProcessedEvent 클래스 추가: 이벤트 데이터 전달을 위한 DTO 구현
  • PaymentEventHandler 컴포넌트 추가: 트랜잭션 커밋 후 외부 알림 처리 담당
  • 예외 처리 강화: @retryable@recover를 활용한 외부 호출 실패 대응
  • Self-invoked 문제 해결: 트랜잭션 메서드와 이벤트 처리를 별도 클래스로 분리
  • 동기 요청 타임아웃 처리: 외부 서버로의 결제 취소 요청(동기)에 timeout 적용

📝 참고 사항

  • PG 서버 상태 저장은 트랜잭션으로 보장하되, 외부 호출 실패가 DB 롤백에 영향을 주지 않도록 하였습니다.
  • 외부 호출 실패 시 최대 3회 재시도 후 실패 로그를 기록합니다.
  • Self-invoked 문제 해결을 위해 웹훅 처리 로직과 이벤트 처리 로직을 별도 컴포넌트로 분리했습니다.

🚀 향후 개선 방향

  • 다양한 PG사별 이벤트 타입 확장 고려
  • 실패한 알림의 재시도 큐 도입 검토

JaesungGo added 14 commits June 13, 2025 23:37
- MerchantRequest: PG -> 가맹점(클라이언트)
- WebhookRequest: PG -> 외부 결제 게이트웨이 (웹훅 요청)
- WebhookResponse: 외부 결제 -> PG (웹훅 응답)
- ApplicationEventPublisher 활용
- 트랜잭션과 외부 호출 분리
- ServletConfig에서 서비스 컴포넌트 스캔을 제거하여 중복 빈 등록 방지
- AsyncConfig에 @EnableRetry를 추가하여 결제 재시도 기능 구현
- 결제 취소 DTO 생성 (CancelRequest)
- 기존 외부 요청 DTO 수정 (WebhookRequest, WebhookResponse)
- Mock 서버 handleCancelData (MockController) 추가
- JSP 뷰 리졸버 설정
- Encoding Filter 설정
- 취소 관련 MockController 수정 -> 메인 스레드 블로킹
- 결제 취소 요청 시 timeout 설정
- JSP 뷰 리졸버 설정
- Encoding Filter 설정
- 취소 관련 MockController 수정 -> 메인 스레드 블로킹
- 결제 취소 요청 시 timeout 설정
@JaesungGo JaesungGo merged commit f36f8fc into main Jun 19, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: WebClientService 외부 요청 실패 처리 및 재시도 로직

1 participant