mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
fix: 保持SSE长连接不断开,移除主动closeConnection逻辑
前端修复: - init()无条件建立SSE连接 - error handler无条件重连,去掉hasActiveTasks判断 后端修复: - notifyAllTasksCompleted不再延迟关闭连接 - SSE保持长连接持续接收任务状态更新
This commit is contained in:
+2
-12
@@ -188,27 +188,17 @@ public class SseNotificationServiceImpl implements SseNotificationService {
|
||||
try {
|
||||
Map<String, Object> completeMessage = new java.util.HashMap<>();
|
||||
completeMessage.put("type", "all_tasks_completed");
|
||||
completeMessage.put("message", "所有任务已完成,可以关闭连接");
|
||||
completeMessage.put("message", "所有任务已完成");
|
||||
|
||||
emitter.send(SseEmitter.event()
|
||||
.name("all_tasks_completed")
|
||||
.data(objectMapper.writeValueAsString(completeMessage)));
|
||||
|
||||
logger.info("通知所有任务已完成,userId: {}", userId);
|
||||
|
||||
// 延迟关闭连接,给前端时间处理
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(1000); // 等待1秒
|
||||
closeConnection(userId);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}).start();
|
||||
// 不再主动关闭连接,让SSE保持长连接,前端持续接收任务更新
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("通知所有任务完成失败,userId: {}", userId, e);
|
||||
closeConnection(userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user