Skip to content

feat: 멱등성 검사로 중복 방어 - #35

Merged
ji-circle merged 3 commits into
devfrom
feat/26-kafka-consumer-idempotency
May 14, 2026
Merged

ji-circle merged 3 commits into
devfrom
feat/26-kafka-consumer-idempotency

Conversation

@ji-circle

@ji-circle ji-circle commented May 14, 2026

Copy link
Copy Markdown
Contributor

📝 작업 내용

이번 PR에서 작업한 내용을 설명해주세요.

  • 카프카 멱등성 방어로 재고 복구 이중 작업 방어

🚀 주요 변경 사항

완료한 이슈 번호
Close #26
관련된 이슈 번호 (닫고 싶지 않은 경우)
Related to #

✅ 자체 체크리스트 (필수)

  • ./gradlew build 실행 결과 정상 (인증샷 첨부)
  • IntelliJ HTTP Client 테스트 완료 (인증샷 첨부)
  • 팀 내 컨벤션 준수 및 불필요한 로그, import 제거
  • 중요한 변경 사항이 팀에 공유되었는지

📸 테스트 인증샷

빌드 결과 및 IntelliJ HTTP Client 실행 화면을 여기에 첨부해 주세요.

스크린샷 2026-05-14 오후 5 23 05 스크린샷 2026-05-14 오후 5 24 01 스크린샷 2026-05-14 오후 5 25 13 스크린샷 2026-05-14 오후 5 25 30

💬 리뷰어 전달사항 (선택)

특별히 봐주었으면 하는 부분이나 논의가 필요한 점을 적어주세요.



📎 참고 자료

관련 문서, 레퍼런스 링크 등이 있다면 여기에 첨부해주세요.

Summary by CodeRabbit

  • 새로운 기능

    • 재고 복구에 멱등성 지원 추가 — 중복 복구 요청은 안전하게 무시됩니다.
  • 사용 중단

    • REST 기반 예약/복구 플로우는 비동기 메시징으로 대체되어 향후 제거 예정입니다.
  • 버그 수정 / 안정성

    • 복구 메시지 식별자 검증 강화 및 처리 로그 개선으로 잘못된/중복 요청 처리 안정성 향상.
  • 테스트

    • 멱등성 및 복구 흐름을 검증하는 단위 테스트 추가/보강.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86030678-9e5e-41cb-9077-a7ba6294922e

📥 Commits

Reviewing files that changed from the base of the PR and between 81df64c and 6b9f3b0.

📒 Files selected for processing (2)
  • src/main/java/com/michelet/inventory/domain/model/ProcessedEvent.java
  • src/main/java/com/michelet/inventory/presentation/dto/ReserveStockRequest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/com/michelet/inventory/presentation/dto/ReserveStockRequest.java
  • src/main/java/com/michelet/inventory/domain/model/ProcessedEvent.java

📝 Walkthrough

Walkthrough

Kafka 재고 복구에 영속적 멱등성 추가: ProcessedEvent 엔티티·리포지토리 도입, StockCommandService.restoreStock에서 existsById 검사·저장, 메시지/요청 검증·컨슈머·테스트·컨트롤러 표시 업데이트.

Changes

Stock Restoration Idempotency

Layer / File(s) Summary
Idempotency Domain Model
src/main/java/com/michelet/inventory/domain/model/ProcessedEvent.java, src/main/java/com/michelet/inventory/domain/repository/ProcessedEventRepository.java
ProcessedEvent JPA 엔티티( eventId PK, processedAt ) 추가 및 ProcessedEventRepositoryexistsById(UUID)/save(ProcessedEvent) 계약 선언.
Repository Infrastructure
src/main/java/com/michelet/inventory/infrastructure/repository/JpaProcessedEventRepository.java, src/main/java/com/michelet/inventory/infrastructure/repository/ProcessedEventRepositoryImpl.java
JpaProcessedEventRepositoryJpaRepository<ProcessedEvent, UUID>를 확장하고, ProcessedEventRepositoryImpl이 JPA 리포지토리에 위임하여 exists/save 구현.
Idempotency Logic in Stock Service
src/main/java/com/michelet/inventory/application/StockCommandService.java
ProcessedEventRepository 주입 및 restoreStock(...)에서 existsById(eventId)로 중복 검사, 정상 복구 경로에서 재고 저장·ProcessedEvent 저장 후 STOCK_RESTORED 아웃박스 이벤트 추가.
Request & Message Contracts
src/main/java/com/michelet/inventory/presentation/dto/RestoreStockRequest.java, src/main/java/com/michelet/inventory/infrastructure/messaging/dto/StockRestoreMessage.java
RestoreStockRequest@NotNull UUID eventId(멱등키)를 사용하도록 변경; StockRestoreMessage 생성자에서 eventId null 검증 추가.
Kafka Consumer Integration
src/main/java/com/michelet/inventory/infrastructure/messaging/OrderEventConsumer.java
컨슈머 로그에 eventId 포함, RestoreStockRequest 생성 시 payload.eventId() 전달(이전 null 대신).
API Deprecation
src/main/java/com/michelet/inventory/presentation/InternalStockController.java
내부 동기 reserve/restore 엔드포인트 섹션에 @Deprecated(since = "1.0", forRemoval = true) 및 JavaDoc 비권장 주석 추가.
Idempotency Test Coverage
src/test/java/com/michelet/inventory/application/StockCommandServiceTest.java
테스트에 ProcessedEventRepository 모크 추가; restoreStock_Success 수정(비중복 eventId), restoreStock_Idempotency 추가(중복 시 무작업) 및 실패 테스트에 eventId 포함.
Reserve DTO Validation
src/main/java/com/michelet/inventory/presentation/dto/ReserveStockRequest.java
ReserveStockRequestoptionId, quantity, reservationId@NotNull 검증 메시지 추가.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Miche-Let/inventory-service#34: Both PRs change the Kafka stock-restore consumer (OrderEventConsumer), including the consumeStockRestoreRequest(...) handler and its use of eventId/restore-request topic wiring.
  • Miche-Let/inventory-service#31: Both PRs modify StockCommandService’s restore-stock flow (notably restoreStock(...) / its Kafka/outbox handling), with main PR adding ProcessedEventRepository idempotency checks while the retrieved PR refactors the method to transactional Redisson-based processing and centralized Kafka publishing.
  • Miche-Let/inventory-service#12: Both PRs modify the stock restore flow (notably StockCommandService and related restore DTO/event wiring), with the main PR adding ProcessedEvent-based idempotency on top of the retrieved PR’s new restore implementation.

Suggested reviewers

  • githyj-jang
  • Jinyoung-Kim96
  • qldo
  • Sehi55
  • jihxonx

Poem

🐇 깡총깡총, 이벤트 왔네 — 기억하는 토끼가 뛰어와,
중복은 멈추고 DB는 조용히,
processedAt에 시간 찍고, eventId는 열쇠,
재고는 한 번만 복구되어 들판엔 평화,
토끼가 깡총, 축하의 당근 한 입!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목 '멱등성 검사로 중복 방어'는 변경사항의 핵심을 명확하게 반영하고 있으며, 멱등성 검사 도입으로 중복을 방어한다는 주요 목표를 잘 표현하고 있습니다.
Linked Issues check ✅ Passed PR의 모든 코드 변경사항이 연결된 이슈 #26의 요구사항을 충족합니다. ProcessedEvent 엔티티 생성, OrderEventConsumer 업데이트, 멱등성 검증 로직 추가, InternalStockController API 지원중단 처리가 모두 구현되었습니다.
Out of Scope Changes check ✅ Passed ReserveStockRequest와 InternalStockController 검증 로직 개선은 기존 동기 API 사용자를 위한 추가 안전 장치로, 이슈 #26의 범위에 부합하는 관련 개선입니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/26-kafka-consumer-idempotency

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@jihxonx jihxonx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다!

@ji-circle
ji-circle merged commit 92652ed into dev May 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] 주문 취소 비동기 전환에 따른 Kafka Consumer 및 멱등성 보장 로직 구현

2 participants