File tree Expand file tree Collapse file tree 6 files changed +20
-14
lines changed
src/main/java/com/somemore Expand file tree Collapse file tree 6 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 55import com .somemore .notification .repository .NotificationRepository ;
66import com .somemore .sse .domain .SseEvent ;
77import com .somemore .sse .domain .SseEventType ;
8- import com .somemore .sse .sender . SseSender ;
8+ import com .somemore .sse .usecase . SseUseCase ;
99import lombok .RequiredArgsConstructor ;
1010import org .springframework .stereotype .Component ;
1111
1414public class NotificationHandlerImpl implements NotificationHandler {
1515
1616 private final NotificationRepository notificationRepository ;
17- private final SseSender sseSender ;
17+ private final SseUseCase sseUseCase ;
1818
1919 @ Override
2020 public void handle (Notification notification ) {
2121 notificationRepository .save (notification );
2222
23- sseSender .send (createSseEvent (notification ));
23+ sseUseCase .send (createSseEvent (notification ));
2424 }
2525
2626 private static SseEvent <NotificationResponseDto > createSseEvent (Notification notification ) {
Original file line number Diff line number Diff line change 11package com .somemore .sse .controller ;
22
33import com .somemore .auth .annotation .CurrentUser ;
4- import com .somemore .global .common .response .ApiResponse ;
54import com .somemore .sse .usecase .SseUseCase ;
65import io .swagger .v3 .oas .annotations .tags .Tag ;
76import lombok .RequiredArgsConstructor ;
87import org .springframework .security .access .annotation .Secured ;
98import org .springframework .web .bind .annotation .GetMapping ;
109import org .springframework .web .bind .annotation .RequestMapping ;
1110import org .springframework .web .bind .annotation .RestController ;
11+ import org .springframework .web .servlet .mvc .method .annotation .SseEmitter ;
1212
1313import java .util .UUID ;
1414
@@ -22,10 +22,9 @@ public class SseController {
2222
2323 @ Secured ({"ROLE_VOLUNTEER" , "ROLE_CENTER" })
2424 @ GetMapping ("/subscribe" )
25- public ApiResponse < String > subscribe (
25+ public SseEmitter subscribe (
2626 @ CurrentUser UUID userId ) {
2727
28- sseUseCase .subscribe (userId );
29- return ApiResponse .ok ("SSE 연결 성공" );
28+ return sseUseCase .subscribe (userId );
3029 }
3130}
Original file line number Diff line number Diff line change 88import lombok .RequiredArgsConstructor ;
99import lombok .extern .slf4j .Slf4j ;
1010import org .springframework .stereotype .Service ;
11+ import org .springframework .web .servlet .mvc .method .annotation .SseEmitter ;
1112
1213import java .util .UUID ;
1314
@@ -20,9 +21,11 @@ public class SseService implements SseUseCase {
2021 private final SseSender sender ;
2122
2223 @ Override
23- public void subscribe (UUID userId ) {
24- subscriptionManager .subscribe (userId );
24+ public SseEmitter subscribe (UUID userId ) {
25+ SseEmitter sseEmitter = subscriptionManager .subscribe (userId );
2526 sendInitMessage (userId );
27+
28+ return sseEmitter ;
2629 }
2730
2831 @ Override
Original file line number Diff line number Diff line change 11package com .somemore .sse .subscriber ;
22
3+ import org .springframework .web .servlet .mvc .method .annotation .SseEmitter ;
4+
35import java .util .UUID ;
46
57public interface SseSubscriptionManager {
68
7- void subscribe (UUID userId );
9+ SseEmitter subscribe (UUID userId );
810}
Original file line number Diff line number Diff line change @@ -16,13 +16,14 @@ public class SseSubscriptionManagerImpl implements SseSubscriptionManager {
1616 private final EmitterRepository emitterRepository ;
1717 private static final Long TIMEOUT_MILLI_SEC = 600_000L ;
1818
19- public void subscribe (UUID userId ) {
20- initEmitter (createEmitterId (userId ));
19+ public SseEmitter subscribe (UUID userId ) {
20+ return initEmitter (createEmitterId (userId ));
2121 }
2222
23- private void initEmitter (String emitterId ) {
23+ private SseEmitter initEmitter (String emitterId ) {
2424 SseEmitter emitter = emitterRepository .save (emitterId , new SseEmitter (TIMEOUT_MILLI_SEC ));
2525 setupLifeCycle (emitter , emitterId );
26+ return emitter ;
2627 }
2728
2829 private String createEmitterId (UUID id ) {
Original file line number Diff line number Diff line change 11package com .somemore .sse .usecase ;
22
33import com .somemore .sse .domain .SseEvent ;
4+ import org .springframework .web .servlet .mvc .method .annotation .SseEmitter ;
45
56import java .util .UUID ;
67
78public interface SseUseCase {
89
9- void subscribe (UUID userId );
10+ SseEmitter subscribe (UUID userId );
1011
1112 <T > void send (SseEvent <T > event );
1213}
You can’t perform that action at this time.
0 commit comments