|
@@ -4,12 +4,14 @@ import com.sxtvs.open.api.review.service.impl.SSEService;
|
|
import com.sxtvs.open.core.auth.LoginRequired;
|
|
import com.sxtvs.open.core.auth.LoginRequired;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
-@RestController
|
|
|
|
|
|
+@Controller
|
|
@RequestMapping("/user")
|
|
@RequestMapping("/user")
|
|
public class SseController {
|
|
public class SseController {
|
|
|
|
|
|
@@ -17,10 +19,9 @@ public class SseController {
|
|
private SSEService sseService;
|
|
private SSEService sseService;
|
|
|
|
|
|
@GetMapping(path = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
@GetMapping(path = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
|
- @LoginRequired
|
|
|
|
- public SseEmitter handleSse() throws InterruptedException {
|
|
|
|
|
|
+ public SseEmitter handleSse(@RequestParam("token") String token) throws InterruptedException {
|
|
SseEmitter sseEmitter = new SseEmitter(0L); // 设置超时时间
|
|
SseEmitter sseEmitter = new SseEmitter(0L); // 设置超时时间
|
|
- sseService.monitor(sseEmitter);
|
|
|
|
|
|
+ sseService.monitor(token, sseEmitter);
|
|
Thread.sleep(500);
|
|
Thread.sleep(500);
|
|
return sseEmitter;
|
|
return sseEmitter;
|
|
}
|
|
}
|