SSEController.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.smcic.api.conference.controller;
  2. import cn.hutool.core.lang.UUID;
  3. import com.smcic.api.conference.service.impl.SSEService;
  4. import com.smcic.core.advice.NoAPIResponse;
  5. import org.springframework.http.MediaType;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.PathVariable;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
  11. import javax.annotation.Resource;
  12. import java.io.IOException;
  13. @Controller
  14. @RequestMapping("/conference")
  15. //@NoAPIResponse
  16. public class SSEController {
  17. @Resource
  18. private SSEService sseService;
  19. /*@GetMapping(path = "/photo-sse/{id}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
  20. @NoAPIResponse
  21. public SseEmitter handleSse(@PathVariable("id") Long id) throws IOException {
  22. String uuid = UUID.fastUUID( ).toString( );
  23. SseEmitter sseEmitter = new SseEmitter(60 * 1000L); // 设置超时时间
  24. sseService.monitor(id, uuid, sseEmitter);
  25. sseEmitter.send(SseEmitter.event().name("hello").data("hello"));
  26. sseEmitter.onCompletion(() -> sseService.complate(id, uuid));
  27. return sseEmitter;
  28. }*/
  29. }