Conversation
개요메모리얼 애플리케이션이 제출될 때 Avro 기반 이벤트를 Kafka로 발행하는 기능이 추가되었습니다. 새로운 Avro 스키마가 정의되고, 매퍼와 서비스가 업데이트되었으며, Kafka 설정이 수정되었습니다. 변경 사항
예상 코드 리뷰 노력🎯 3 (Moderate) | ⏱️ ~20-30분
관련 가능성 있는 PR
시
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/example/memorial_application/domain/service/MemorialApplicationCommandService.java (1)
33-51:apply()메서드에@Transactional누락 확인다른 변경 작업 메서드들(
reject,approve,cancel,delete,update)은@Transactional이 적용되어 있지만apply()메서드에는 없습니다. 현재 로직에서는 단일 save 작업이지만, 향후 확장성과 일관성을 위해 트랜잭션 적용을 고려해 주세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.github/workflows/deploy.yml(1 hunks)src/main/avro/MemorialAppliedAvroSchema.avsc(1 hunks)src/main/java/com/example/memorial_application/domain/mapper/MemorialApplicationMapper.java(2 hunks)src/main/java/com/example/memorial_application/domain/service/MemorialApplicationCommandService.java(2 hunks)src/main/resources/application.yml(1 hunks)src/test/java/com/example/memorial_application/domain/service/MemorialApplicationApproveServiceTest.java(6 hunks)
🔇 Additional comments (8)
.github/workflows/deploy.yml (1)
14-14: 워크플로우 참조 변경 확인 필요CI 워크플로우에서
release.yml로 변경되었습니다. 이 변경이 의도된 것인지, 그리고 release 워크플로우가 기존 CI 워크플로우와 동일한 입력 파라미터를 지원하는지 확인해 주세요.src/main/resources/application.yml (1)
39-40:auto-offset-reset: latest변경 확인 필요
auto-offset-reset이earliest에서latest로 변경되었습니다. 이 설정은 새로운 consumer group이 기존 메시지를 읽지 않고 새 메시지부터 소비하게 됩니다. 서비스 재시작 또는 새 consumer 배포 시 메시지 유실 가능성이 있으므로 의도된 변경인지 확인해 주세요.src/main/java/com/example/memorial_application/domain/mapper/MemorialApplicationMapper.java (1)
51-58: LGTM!
toMemorialAppliedAvroSchema매핑 메서드가 깔끔하게 구현되었습니다. 기존toMemorialApplicationAvroSchema메서드와 일관된 패턴을 따르고 있습니다.src/main/avro/MemorialAppliedAvroSchema.avsc (1)
1-12: LGTM!Avro 스키마가 잘 정의되었습니다. 각 필드에 대한 문서화가 적절하며,
MemorialApplicationMapper의 매핑 로직과 필드 타입이 일치합니다.src/test/java/com/example/memorial_application/domain/service/MemorialApplicationApproveServiceTest.java (4)
18-18: 새로운 Avro 스키마 추가가 적절합니다.
MemorialAppliedAvroSchema임포트 및 필드 선언이 기존 패턴을 잘 따르고 있습니다.Also applies to: 55-55
67-74: setUp 메서드 업데이트가 올바릅니다.새로운 스키마의 mock 초기화와 필요한 stub 설정이 적절하게 추가되었습니다.
84-91: apply 테스트의 이벤트 발행 로직이 정확히 구현되어 있습니다.
MemorialApplicationMapper.toMemorialAppliedAvroSchema()메서드가 구현되어 있고,MemorialApplicationCommandService에서 "memorial-apply-request" 토픽으로 올바르게 이벤트를 발행하고 있습니다. 테스트 코드가 실제 구현과 일치합니다.
119-119: 토픽명 검증 완료: 구현과 테스트 일치Kafka 토픽명 "memorial-application-approved-request"이
MemorialApplicationCommandService.java59번 라인의 서비스 구현과 테스트 코드에서 일치하게 사용되고 있습니다. 승인 흐름이 올바르게 정의되어 있습니다.
| MemorialApplication savedMemorialApplication = memorialApplicationRepository.save(memorialApplication); | ||
|
|
||
| MemorialAppliedAvroSchema memorialAppliedAvroSchema = memorialApplicationMapper.toMemorialAppliedAvroSchema(savedMemorialApplication); | ||
| kafkaProducer.send("memorial-apply-request", memorialAppliedAvroSchema); |
There was a problem hiding this comment.
DB 저장과 Kafka 발행 간 데이터 일관성 고려 필요
apply() 메서드에서 DB 저장 후 Kafka 메시지를 발행합니다. 만약 kafkaProducer.send() 호출이 실패하면 DB에는 레코드가 저장되지만 이벤트는 발행되지 않아 XP가 누락될 수 있습니다.
다음 방안을 고려해 보세요:
- Outbox 패턴 사용
- 트랜잭션 내에서 이벤트 저장 후 별도 프로세스로 발행
- 실패 시 재시도 로직 또는 보상 처리
🤖 Prompt for AI Agents
In
src/main/java/com/example/memorial_application/domain/service/MemorialApplicationCommandService.java
around lines 47–50, the code saves the entity to the DB then directly calls
kafkaProducer.send, which can lead to DB-event inconsistency if sending fails;
instead, persist the event atomically with the entity (Outbox pattern) by adding
an OutboxEvent entity/table and saving the memorialApplication and corresponding
OutboxEvent within the same transaction, then remove the direct
kafkaProducer.send call and implement/trigger a separate reliable dispatcher
that reads unsent OutboxEvent rows, publishes them to Kafka with
retries/backoff, and marks them sent (or use a transactional event log +
background publisher); alternatively implement transactional publish via a
two-phase approach or compensate on failure, but prefer the Outbox pattern for
guaranteed consistency.
Summary by CodeRabbit
릴리스 노트
새로운 기능
버그 수정
기타
✏️ Tip: You can customize this high-level summary in your review settings.