사용자 도구

사이트 도구


springframework:httpstream

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
springframework:httpstream [2018/12/26 15:54]
kwon37xi
springframework:httpstream [2022/01/04 17:00] (현재)
kwon37xi [ServerSentEvent Reverse Proxy(nginx) 설정]
줄 3: 줄 3:
   * [[springframework:webflux|Spring WebFlux]] 사용시 더 깔끔하다.   * [[springframework:webflux|Spring WebFlux]] 사용시 더 깔끔하다.
  
 +===== ServerSentEvent Reverse Proxy(nginx) 설정 =====
 +  * [[:nginx|Ngnix]] 같은 reverse proxy 사용시에 buffering 을 끄는 등의 별도 설정이 필요하다.
 +
 +
 +  * [[https://serverfault.com/questions/801628/for-server-sent-events-sse-what-nginx-proxy-configuration-is-appropriate|For Server-Sent Events (SSE) what Nginx proxy configuration is appropriate? - Server Fault]]
 +  * [[https://github.com/wandenberg/nginx-push-stream-module|wandenberg/nginx-push-stream-module: A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.]]
 +  * 서버측에서 ''X-Accel-Buffering: no'' 응답 헤더를 내려주면 SSE 커넥션만 버퍼링 방지.
 +  * [[https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/|nginx x-accel-* 헤더를 통한 응답 제어]]
 +<code java>
 +@RequestMapping("/sseExamples")
 +public SseEmitter getRealTimeJudgeResultAction(HttpServletResponse response) throws IOException {
 +    // ....
 +    response.addHeader("X-Accel-Buffering", "no");
 +    SseEmitter sseEmitter = new SseEmitter();
 +    // ....
 +    sseEmitter.send("Established");
 +    return sseEmitter;
 +}
 +</code>
 +<code>
 +# 응답 결과를 보면 X-Accel-Buffering: no 헤더가 출력됨.
 +curl -D - http://....
 +HTTP/1.1 200
 +X-Accel-Buffering: no
 +Content-Type: text/event-stream
 +Transfer-Encoding: chunked
 +...
 +</code>
 +  * nginx 의 SSE 관련 url 프록시에 대해서만 ''proxy_buffering off;'' 및 기타 설정.
 +  * [[https://stackoverflow.com/questions/13672743/eventsource-server-sent-events-through-nginx|ruby - EventSource / Server-Sent Events through Nginx - Stack Overflow]] - https://stackoverflow.com/a/13673298/1051402
 +
 +<code>
 +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;
 +}
 +</code>
 +  * [[https://medium.com/tokopedia-engineering/server-sent-events-26f75e3a5ed2|Server Sent Events. File Upload Progress API using Server… | by Somesh Singh | Tokopedia Engineering | Medium]] : 좀 더 잘 설명돼 있는 듯.
 ===== 참고 ===== ===== 참고 =====
   * [[https://supawer0728.github.io/2018/03/15/spring-http-stereamings/|Spring5에서 HTTP Streaming | 기록은 재산이다]]   * [[https://supawer0728.github.io/2018/03/15/spring-http-stereamings/|Spring5에서 HTTP Streaming | 기록은 재산이다]]
줄 8: 줄 51:
   * [[https://medium.com/@nithinmallya4/processing-streaming-data-with-spring-webflux-ed0fc68a14de|Processing streaming data with Spring WebFlux – Nithin Mallya – Medium]]   * [[https://medium.com/@nithinmallya4/processing-streaming-data-with-spring-webflux-ed0fc68a14de|Processing streaming data with Spring WebFlux – Nithin Mallya – Medium]]
   * [[https://www.baeldung.com/spring-mvc-sse-streams|Spring MVC Streaming and SSE Request Processing | Baeldung]]   * [[https://www.baeldung.com/spring-mvc-sse-streams|Spring MVC Streaming and SSE Request Processing | Baeldung]]
 +  * [[https://www.baeldung.com/spring-server-sent-events|Server-Sent Events in Spring | Baeldung]]
   * [[https://dzone.com/articles/event-streaming-using-spring-webflux|Event Streaming Using Spring WebFlux - DZone Java]]   * [[https://dzone.com/articles/event-streaming-using-spring-webflux|Event Streaming Using Spring WebFlux - DZone Java]]
springframework/httpstream.1545807240.txt.gz · 마지막으로 수정됨: 2018/12/26 15:54 저자 kwon37xi