diff --git a/src/main/java/com/api/trip/common/sse/emitter/SseEmitterMap.java b/src/main/java/com/api/trip/common/sse/emitter/SseEmitterMap.java index c45455d..4664b2a 100644 --- a/src/main/java/com/api/trip/common/sse/emitter/SseEmitterMap.java +++ b/src/main/java/com/api/trip/common/sse/emitter/SseEmitterMap.java @@ -15,22 +15,22 @@ @Slf4j public class SseEmitterMap { - private final Map sseEmitterMap = new ConcurrentHashMap<>(); + private final Map sseEmitterMap = new ConcurrentHashMap<>(); - public void put(Long memberId, SseEmitter sseEmitter) { - sseEmitter.onCompletion(() -> remove(memberId)); + public void put(String email, SseEmitter sseEmitter) { + sseEmitter.onCompletion(() -> remove(email)); sseEmitter.onTimeout(sseEmitter::complete); - sseEmitterMap.put(memberId, sseEmitter); - log.info("connected with {}, the number of connections is {}", memberId, sseEmitterMap.size()); + sseEmitterMap.put(email, sseEmitter); + log.info("connected with {}, the number of connections is {}", email, sseEmitterMap.size()); } - public void remove(Long memberId) { - sseEmitterMap.remove(memberId); - log.info("disconnected with {}, the number of connections is {}", memberId, sseEmitterMap.size()); + public void remove(String email) { + sseEmitterMap.remove(email); + log.info("disconnected with {}, the number of connections is {}", email, sseEmitterMap.size()); } - public void send(Long memberId, String eventName, Object eventData) { - SseEmitter sseEmitter = sseEmitterMap.get(memberId); + public void send(String email, String eventName, Object eventData) { + SseEmitter sseEmitter = sseEmitterMap.get(email); try { sseEmitter.send( event() @@ -38,17 +38,17 @@ public void send(Long memberId, String eventName, Object eventData) { .data(eventData) ); } catch (IOException | IllegalStateException e) { - remove(memberId); + remove(email); } } public void sendToAll(String eventName, Object eventData) { SseEventBuilder sseEventBuilder = event().name(eventName).data(eventData); - sseEmitterMap.forEach((memberId, sseEmitter) -> { + sseEmitterMap.forEach((email, sseEmitter) -> { try { sseEmitter.send(sseEventBuilder); } catch (IOException | IllegalStateException e) { - remove(memberId); + remove(email); } }); } diff --git a/src/main/java/com/api/trip/domain/notification/controller/NotificationController.java b/src/main/java/com/api/trip/domain/notification/controller/NotificationController.java index afc631a..75b151c 100644 --- a/src/main/java/com/api/trip/domain/notification/controller/NotificationController.java +++ b/src/main/java/com/api/trip/domain/notification/controller/NotificationController.java @@ -1,9 +1,6 @@ package com.api.trip.domain.notification.controller; -import com.api.trip.common.exception.CustomException; -import com.api.trip.common.exception.ErrorCode; import com.api.trip.common.sse.emitter.SseEmitterMap; -import com.api.trip.domain.member.repository.MemberRepository; import com.api.trip.domain.notification.controller.dto.DeleteNotificationRequest; import com.api.trip.domain.notification.controller.dto.GetMyNotificationsResponse; import com.api.trip.domain.notification.controller.dto.ReadNotificationRequest; @@ -22,20 +19,15 @@ @RequiredArgsConstructor public class NotificationController { - private final MemberRepository memberRepository; private final NotificationService notificationService; private final SseEmitterMap sseEmitterMap; @GetMapping(value = "/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public ResponseEntity connect() { String email = SecurityContextHolder.getContext().getAuthentication().getName(); - Long memberId = memberRepository.findByEmail(email) - .orElseThrow(() -> new CustomException(ErrorCode.UNAUTHORIZED)) - .getId(); - SseEmitter sseEmitter = new SseEmitter(3600000L); - sseEmitterMap.put(memberId, sseEmitter); - sseEmitterMap.send(memberId, "connect", LocalDateTime.now()); + sseEmitterMap.put(email, sseEmitter); + sseEmitterMap.send(email, "connect", LocalDateTime.now()); return ResponseEntity.ok(sseEmitter); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 085b034..5ada501 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,6 @@ spring: profiles: active: dev - datasource: - hikari: - maximum-pool-size: 4 h2: console: enabled: true