Skip to content

Commit

Permalink
Merge pull request #123 from H-Hive/feature/notification
Browse files Browse the repository at this point in the history
fix: 알림 변경3
  • Loading branch information
mixedtape authored Feb 2, 2024
2 parents 6ca3320 + e945908 commit d4b1068
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -37,11 +38,10 @@ public ResponseEntity<CommonResponse> sendNotification(
}


@GetMapping(value = "/{userId}/get")
@GetMapping(value = "/{userId}/get",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public ResponseEntity<SseEmitter> handleNotifications(
@PathVariable(name = "userId") Long userId
) {

SseEmitter emitter = notificationService.addSseEmitter(userId);

return ResponseEntity.ok(emitter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public class NotificationService {


public SseEmitter addSseEmitter(Long userId) {
SseEmitter emitter = new SseEmitter(600000L);
SseEmitter emitter = new SseEmitter(300000L);
try {
emitter.send(SseEmitter.event().name("connect").data("connect"));
} catch (Exception e) {
System.err.println("연결 실패");
}
emitterRepository.add(userId, emitter);
emitter.onCompletion(() -> {
emitterRepository.remove(userId);
Expand Down

0 comments on commit d4b1068

Please sign in to comment.