-
Notifications
You must be signed in to change notification settings - Fork 16
[김찬호] Sprint11 #152
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
base: 김찬호
Are you sure you want to change the base?
[김찬호] Sprint11 #152
Conversation
| this.binaryContentService = binaryContentService; | ||
| } | ||
|
|
||
| @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phase = TransactionPhase.AFTER_COMMIT 이게 기본값이긴 한데, 의도를 표현하기 위해 명시적으로 남겨두신걸까요?
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.retry.annotation.EnableRetry; | ||
|
|
||
| @EnableRetry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어플리케이션 컨피그를 따로 만들고 추가하시는게 훨씬 책임을 분리한 좋은 코드가 될 것 같아요.
|
Retryable 을 통해 재시도 설정하는 부분이 누락되신것 같아요! |
| this.userRepository = userRepository; | ||
| } | ||
|
|
||
| @Cacheable("notifications") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
캐싱하실때 키 설정을 명시적으로 하시는것을 추천드립니다.
요구사항
기본
Spring Event - 파일 업로드 로직 분리하기
디스코드잇은 BinaryContent의 메타 데이터(DB)와 바이너리 데이터(FileSystem/S3)를 분리해 저장합니다.
만약 지금처럼 두 로직이 하나의 트랜잭션으로 묶인 경우 트랜잭션을 과도하게 오래 점유할 수 있는 문제가 있습니다.
따라서 Spring Event를 활용해 메타 데이터 저장 트랜잭션으로부터 바이너리 데이터 저장 로직을 분리하여, 메타데이터 저장 트랜잭션이 종료되면 바이너리 데이터를 저장하도록 변경합니다.
BinaryContentStorage.put을 직접 호출하는 대신 BinaryContentCreatedEvent를 발행하세요.
BinaryContentCreatedEvent를 정의하세요.
다음의 메소드에서 BinaryContentStorage를 호출하는 대신 BinaryContentCreatedEvent를 발행하세요.
ApplicationEventPublisher를 활용하세요.
이벤트를 받아 실제 바이너리 데이터를 저장하는 리스너를 구현하세요.
이벤트를 발행한 메인 서비스의 트랜잭션이 커밋되었을 때 리스너가 실행되도록 설정하세요.
BinaryContentStorage를 통해 바이너리 데이터를 저장하세요.
바이너리 데이터 저장 성공 여부를 메타 데이터에 반영하세요.
성공 시 BinaryContent의 status를 SUCCESS로 업데이트하세요.
실패 시 BinaryContent의 status를 FAIL로 업데이트하세요.
Spring Event - 알림 기능 추가하기
채널에 새로운 메시지가 등록된 경우 알림을 받을 수 있도록 리팩토링하세요.
MessageCreatedEvent를 정의하고 새로운 메시지가 등록되면 이벤트를 발행하세요.
사용자 별로 관심있는 채널의 알림만 받을 수 있도록 ReadStatus 엔티티에 채널 알림 여부 속성(notificationEnabled)을 추가하세요.
알림 조회
알림 확인
비동기 적용하기
메시지 생성 API의 실행 시간을 측정해보세요.
비동기 실패 처리하기
재시도가 모두 실패했을 때 대응 전략을 구축하세요.
@recover 어노테이션을 활용하세요.
실패 정보를 관리자에게 통지하세요.
캐시 적용하기
심화
유의사항
Spring Kafka 도입하기
Spring Event를 Kafka로 발행하는 리스너를 구현하세요.
NotificationRequiredEventListener는 비활성화하세요.
KafkaProduceRequiredEventListener를 구현하세요.
60f20el76-image.png
Kafka Console을 통해 Kafka 이벤트가 잘 발행되는지 확인해보세요.
Kafka 토픽을 구독해 알림을 생성하는 리스너를 구현하세요.
이 리스너는 메인 서비스와 별도의 서버로 구성된 알림 서비스라고 가정합니다.
NotificationRequiredTopicListener를 구현하세요.
Redis Cache 도입하기
대용량 트래픽을 감당하기 위해 서버의 인스턴스를 여러 개로 늘렸다고 가정해봅시다.
Caffeine과 같은 로컬 캐시는 서로 다른 서버에서 더 이상 활용할 수 없습니다.
따라서 Redis를 통해 전역 캐시 저장소를 구성합니다.
Redis 환경을 구성하세요.
Docker Compose를 활용해 Redis를 구동하세요.
주요 변경사항
스크린샷
멘토에게