Skip to content

Commit ada3aaf

Browse files
authored
Merge pull request #331 from Kernel360/fix/#326-fix-SSE-alarm
fix: X-Accel-Buffering을 사용하여 SSE 응답만 버퍼링하지 않도록 수정
2 parents b549e2c + 371fbc0 commit ada3aaf

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

monicar-control-center/src/main/java/org/controlcenter/alarm/presentation/AlarmController.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.controlcenter.alarm.presentation;
22

3+
import jakarta.servlet.http.HttpServletResponse;
4+
35
import org.controlcenter.alarm.application.AlarmService;
46
import org.controlcenter.alarm.domain.AlarmStatus;
57
import org.controlcenter.alarm.presentation.dto.AlarmResponse;
@@ -37,9 +39,12 @@ public class AlarmController implements AlarmApi {
3739

3840
private final AlarmService alarmService;
3941

40-
@GetMapping(value = "/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
42+
@GetMapping(value = "/subscribe")
4143
@PreAuthorize("hasRole('ROLE_USER')")
42-
public SseEmitter subscribe(@AuthenticationPrincipal CustomUserDetails user) {
44+
public SseEmitter subscribe(
45+
HttpServletResponse response,
46+
@AuthenticationPrincipal CustomUserDetails user) {
47+
response.setHeader("X-Accel-Buffering", "no");
4348
return alarmService.subscribe(user.getId());
4449
}
4550

monicar-control-center/src/main/java/org/controlcenter/alarm/presentation/swagger/AlarmApi.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515

1616
import io.swagger.v3.oas.annotations.Operation;
1717
import io.swagger.v3.oas.annotations.tags.Tag;
18+
import jakarta.servlet.http.HttpServletResponse;
1819
import jakarta.validation.Valid;
1920

2021
@Tag(name = "실시간 알람 API", description = "실시간 알람 API")
2122
public interface AlarmApi {
2223
@Operation(summary = "SSE 구독", description = "SSE 구독")
23-
SseEmitter subscribe(@AuthenticationPrincipal CustomUserDetails user);
24+
SseEmitter subscribe(
25+
HttpServletResponse response, @AuthenticationPrincipal CustomUserDetails user);
2426

2527
@Operation(summary = "알람 승인 API", description = "점검 필요 -> 점검 예정 -> 점검 진행 -> 점검 완료로 순차적으로 상태 변경")
2628
void next(

0 commit comments

Comments
 (0)