-
Notifications
You must be signed in to change notification settings - Fork 16
[문은서] Sprint11 #156
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: main
Are you sure you want to change the base?
[문은서] Sprint11 #156
Conversation
| private final BinaryContentStorage binaryContentStorage; | ||
| private final 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.
이벤트 소비
| public void handle(BinaryContentCreatedEvent event) { | ||
| try { | ||
| binaryContentStorage.put(event.binaryContentId(), event.bytes()); | ||
| binaryContentService.updateStatus(event.binaryContentId(), BinaryContentStatus.SUCCESS); |
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.
상태 변경 처리
| contentType | ||
| ); | ||
| binaryContentRepository.save(binaryContent); | ||
| eventPublisher.publishEvent(new BinaryContentCreatedEvent(binaryContent.getId(), bytes)); |
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.
이벤트 발행
| @Async("eventTaskExecutor") | ||
| @TransactionalEventListener | ||
| public void on(MessageCreatedEvent event) { | ||
| try { | ||
| log.info("🔥 Kafka 이벤트 수신됨: {}", event); | ||
| String payload = objectMapper.writeValueAsString(event); | ||
| kafkaTemplate.send("discodeit.MessageCreatedEvent", payload); | ||
| log.info("✅ Kafka 메시지 전송 완료: {}", payload); | ||
| } catch (JsonProcessingException e) { | ||
| log.error("Kafka 메세지 변환 실패", e); | ||
| } | ||
| } |
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.
비동기 처리
| private final NotificationMapper notificationMapper; | ||
|
|
||
| @Override | ||
| @Cacheable(value = "notifications", key = "#userId") |
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.
캐시 설정
| return channelMapper.toDto(channel); | ||
| } | ||
|
|
||
| @CacheEvict(value = {"channelById", "channelsByUserId"}, allEntries = true) |
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.
캐시 만료 설정
| @Bean | ||
| public RedisCacheConfiguration redisCacheConfiguration(ObjectMapper objectMapper) { | ||
| ObjectMapper redisObjectMapper = objectMapper.copy(); | ||
| redisObjectMapper.activateDefaultTyping( | ||
| LaissezFaireSubTypeValidator.instance, | ||
| DefaultTyping.EVERYTHING, | ||
| As.PROPERTY | ||
| ); | ||
|
|
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 - 파일 업로드 로직 분리하기
BinaryContentStorage.put을 직접 호출하는 대신 BinaryContentCreatedEvent를 발행하세요.
이벤트를 받아 실제 바이너리 데이터를 저장하는 리스너를 구현하세요.
바이너리 데이터 저장 성공 여부를 알 수 있도록 메타 데이터를 리팩토링하세요.
BinaryContent에 바이너리 데이터 업로드 상태 속성(status)을 추가하세요.
BinaryContent의 상태를 업데이트하는 메소드를 정의하세요.
3o66puyre-image.png
트랜잭션 전파 범위에 유의하세요.
바이너리 데이터 저장 성공 여부를 메타 데이터에 반영하세요.
Spring Event - 알림 기능 추가하기
1)채널에 새로운 메시지가 등록되거나 2)권한이 변경된 경우 이벤트를 발행해 알림을 받을 수 있도록 구현합니다.
채널에 새로운 메시지가 등록된 경우 알림을 받을 수 있도록 리팩토링하세요.
사용자의 권한(Role)이 변경된 경우 알림을 받을 수 있도록 리팩토링하세요.
알림 API를 구현하세요.
receiverId: 알림을 수신할 User의 id입니다.
알림이 필요한 이벤트가 발행되었을 때 알림을 생성하세요.
해당 채널의 알림 여부를 활성화한 ReadStatus를 조회합니다.
해당 ReadStatus의 사용자들에게 알림을 생성합니다.
단, 해당 메시지를 보낸 사람은 알림 대상에서 제외합니다.
on(RoleUpdatedEvent)
권한이 변경된 당사자에게 알림을 생성합니다.
비동기 적용하기
비동기 실패 처리하기
1ubhvrs9g-image.png
캐시 적용하기
심화
Spring Kafka 도입하기
Spring Event를 Kafka로 발행하는 리스너를 구현하세요.
NotificationRequiredEventListener는 비활성화하세요.
KafkaProduceRequiredEventListener를 구현하세요.
Redis Cache 도입하기
주요 변경사항
스크린샷
멘토에게