목차

Spring HTTP Streaming

ServerSentEvent Reverse Proxy(nginx) 설정

@RequestMapping("/sseExamples")
public SseEmitter getRealTimeJudgeResultAction(HttpServletResponse response) throws IOException {
    // ....
    response.addHeader("X-Accel-Buffering", "no");
    SseEmitter sseEmitter = new SseEmitter();
    // ....
    sseEmitter.send("Established");
    return sseEmitter;
}
# 응답 결과를 보면 X-Accel-Buffering: no 헤더가 출력됨.
curl -D - http://....
HTTP/1.1 200
X-Accel-Buffering: no
Content-Type: text/event-stream
Transfer-Encoding: chunked
...
location /path/to/sse {
  proxy_pass http://upstream;
  proxy_buffering off; # X-Accel-Buffering: no 와 같은 효과
  proxy_cache off;
  proxy_set_header Host $host;
  proxy_set_header Connection '';
  proxy_http_version 1.1;
  chunked_transfer_encoding off;
}

참고