diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SSEController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SSEController.java deleted file mode 100644 index 01cbb043..00000000 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SSEController.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.jeecg.modules.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@RestController -@RequestMapping("sse") -public class SSEController { - private static Map sseCache = new ConcurrentHashMap<>(); - - @GetMapping("subscribe") - public SseEmitter subscribe(String id) { - // 超时时间设置为1小时 - SseEmitter sseEmitter = new SseEmitter(3600_000L); - sseCache.put(id, sseEmitter); - sseEmitter.onTimeout(() -> sseCache.remove(id)); - sseEmitter.onCompletion(() -> System.out.println("完成!!!")); - return sseEmitter; - } - - @GetMapping("push") - public String push(String id, String content) throws IOException { - SseEmitter sseEmitter = sseCache.get(id); - if (sseEmitter != null) { - sseEmitter.send(content); - } - return "over"; - } - - @GetMapping("over") - public String over(String id) { - SseEmitter sseEmitter = sseCache.get(id); - if (sseEmitter != null) { - sseEmitter.complete(); - sseCache.remove(id); - } - return "over"; - } - -}