STK10-02 KRX MDC client (OTP·재시도·백오프)
작업 내용
KRX 정보데이터시스템 호출을 캡슐화하는 저수준 client를 infrastructure/krx에 신설한다. 팩터별 GatewayImpl이 공유하는 공통 병목이다.
KrxMdcClient—bld와 파라미터를 받아generate.cmd로 OTP 발급 →getJsonData.cmdPOST → JSON rows 반환 (Spring RestClient)- 4xx/5xx·차단 응답에 재시도 + 지수 백오프, 호출 간 간격 (ADR-004)
- 토스 어댑터처럼 외부 호출은 infrastructure에 격리, 도메인 비참조
이 티켓은 client 자체만 제공한다. 팩터별 파싱·Gateway는 STK10-03~07이 각자 소유한다.
다이어그램
처리 흐름
sequenceDiagram participant Caller as GatewayImpl participant Client as KrxMdcClient participant KRX as data.krx.co.kr Caller->>Client: getJsonData(bld, params) Client->>KRX: generate.cmd(bld) KRX-->>Client: otp Client->>KRX: getJsonData.cmd(otp, params) alt 5xx/차단 Client->>KRX: retry (backoff) end KRX-->>Client: json rows Client-->>Caller: rows
클래스 의존
flowchart LR Gw["Krx*GatewayImpl (STK10-03~07)"] --> Client[KrxMdcClient] Client --> RestClient
테스트 케이스
- 정상 응답 시 OTP 발급 후 getJsonData로 rows를 반환한다 (MockWebServer)
- 5xx 응답 시 백오프 후 재시도하고 최종 성공하면 rows를 반환한다
- 재시도 한도 초과 시 예외를 던진다
- 빈 결과(rows 없음)를 빈 리스트로 graceful 반환한다
- OTP 발급 실패 시 getJsonData를 호출하지 않고 예외를 던진다